Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ app.get('/index.html',
function (req, res) { ... });
```

Also, you can use `res.express_redis_cache_expire` to change expiration:

```js
app.post('/expensive-query-service',
function (req, res, next) {
// set expiration
res.express_redis_cache_expire = 20; // (for example: req.body.expire - user defined expiration from request)
next();
},

// cache middleware
cache.route(), // cache.route(15) will override express_redis_cache_expire to this value (15)

// content middleware
function (req, res) {
res.render('query result');
}
);
```

You can also specify

# Content Type
Expand Down
5 changes: 5 additions & 0 deletions lib/ExpressRedisCache/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ module.exports = (function () {
* @default this.expire
*/
var expire = self.expire;

if ( typeof res.express_redis_cache_expire === 'number' && ! isNaN(res.express_redis_cache_expire) ) {
expire = res.express_redis_cache_expire;
}

if ( typeof options[0] === 'object' ) {
if ( typeof options[0].expire === 'number' || typeof options[0].expire === 'object' || typeof options[0].expire === 'function') {
expire = options[0].expire;
Expand Down