Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ttl in wrap #14

Merged
merged 2 commits into from
Oct 15, 2014
Merged

Set ttl in wrap #14

merged 2 commits into from
Oct 15, 2014

Conversation

nguyenchr
Copy link

As discussed in #12

This allows different ttl values to be set per function that is being wrapped

For example

var getShortLivedField = function(id, callback) {
  ...
}

var getLongLivedField = function(id, callback) {
  ...
}

app.get('/short/lived', function(req, res) {
  var cache_key = "short:" + req.params.id;
  var ttl = 1;
  cache.wrap(cache_key, function(cache_cb) {
    getShortLivedField(req.params.id, cache_cb);
  }, ttl, function(err,result){
    res.send(result);
  });
})

app.get('/long/lived', function(req, res) {
  var cache_key = "long:" + req.params.id;
  var ttl = 600;
  cache.wrap(cache_key, function(cache_cb) {
    getLongLivedField(req.params.id, cache_cb);
  }, ttl, function(err,result){
    res.send(result);
  });
})

ttl is optional in wrap(), if it is not passed in then cache.set will be called with a ttl of undefined

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 0f685c5 on nguyenchr:set-ttl-in-wrap into 1d352ed on BryanDonovan:master.

BryanDonovan added a commit that referenced this pull request Oct 15, 2014
@BryanDonovan BryanDonovan merged commit 3355d95 into jaredwray:master Oct 15, 2014
@BryanDonovan
Copy link
Collaborator

Thanks, I'll cut a new release version asap

@BryanDonovan
Copy link
Collaborator

This is merged into 0.14.0. Thanks again!

@nguyenchr nguyenchr deleted the set-ttl-in-wrap branch October 15, 2014 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants