Skip to content

Commit ed0a42e

Browse files
committed
Merge branch 'release/2.4.0'
2 parents 2b60fae + 4c632f6 commit ed0a42e

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

History.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- 2.4.0 2017-01-17
2+
- Added ability to use a dynamic cache ttl (#65) - @philippeauriach
3+
14
- 2.3.0 2016-12-22
25
- Updating isCacheableValue description in README; README syntax error fix (#70, #71) - @lukechilds
36
- Calling back with null as first argument in memory store to keep style consistent (#72) - @defcc

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ memoryCache.wrap(key, function (cb) {
152152
// { id: 123, name: 'Bob' }
153153
```
154154

155+
The `ttl` can also be computed dynamicall by passing in a function. E.g.,
156+
157+
```javascript
158+
var opts = {
159+
ttl: function(user) {
160+
if (user.id === 1) {
161+
return 0.1;
162+
} else {
163+
return 0.5;
164+
}
165+
}
166+
};
167+
168+
memoryCache.wrap(key, function(cb) {
169+
getUser(userId, cb);
170+
}, opts, function(err, user) {
171+
console.log(user);
172+
}
173+
```
174+
155175
#### Example Using Promises
156176
157177
```javascript

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cache-manager",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "Cache module for Node.js",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)