Skip to content

Commit 7fb808e

Browse files
author
Bryan Donovan
committed
Merge branch 'release/4.1.0'
2 parents 3151a56 + 199eb06 commit 7fb808e

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

History.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- 4.1.0
2+
- Support for TTL as third arg in memory store set function (#196). - @ZirionNeft
3+
14
- 4.0.1
25
- Fix TTL option bug for memory cache (#194). - @anchan828
36

lib/stores/memory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ var memoryStore = function(args) {
6464
}
6565
options = options || {};
6666

67+
if (options && typeof options === 'number') {
68+
options = {ttl: options};
69+
}
70+
6771
var ttl = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.ttl;
6872

6973
lruCache.set(key, value, {ttl});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cache-manager",
3-
"version": "4.0.1",
3+
"version": "4.1.0",
44
"description": "Cache module for Node.js",
55
"main": "index.js",
66
"files": [

test/stores/memory.unit.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ describe("memory store", function() {
3737
});
3838
});
3939

40+
describe("ttl", function() {
41+
var memoryCache;
42+
43+
beforeEach(function() {
44+
memoryCache = memoryStore.create({noPromises: true});
45+
});
46+
47+
it("if options arg is a number in set()", function(done) {
48+
memoryCache.set('foo', 'bar', 60);
49+
50+
setTimeout(function() {
51+
assert.equal(memoryCache.get('foo'), 'bar');
52+
done();
53+
}, 10);
54+
});
55+
56+
it("cache record should be expired", function(done) {
57+
memoryCache.set('foo', 'bar', 0.001);
58+
59+
setTimeout(function() {
60+
assert.equal(memoryCache.get('foo'), undefined);
61+
done();
62+
}, 1);
63+
});
64+
});
65+
4066
describe("keyCount", function() {
4167
var memoryCache;
4268

0 commit comments

Comments
 (0)