Skip to content

Commit

Permalink
Fix default ttl regression
Browse files Browse the repository at this point in the history
Numeric defaults broke due to a lack of string check
  • Loading branch information
dantman committed Jan 8, 2016
1 parent fe7897c commit 7adb4e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export default class Cacheman {
ttl = 60
} = options;

ttl = Math.round(ms(ttl)/1000);
if (ttl) {
if ('string' === typeof ttl) {
ttl = Math.round(ms(ttl)/1000);
}
}

prefix = [prefix, name || 'cache', ''].join(delimiter);
this.options = { ...options, Promise: _Promise, delimiter, prefix, ttl, count: 1000 };
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ describe('cacheman', function () {
assert.equal(c3._prefix, 'myprefix:foo:');
});

it('should have a default ttl', function () {
assert.equal(cache._ttl, 60);
assert.equal(cache.options.ttl, 60);
})

it('should not allow invalid keys', function (done) {
let msg = 'Invalid key, key must be a string or array.';
cache.set(1, {}, function (err) {
Expand Down

0 comments on commit 7adb4e2

Please sign in to comment.