Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-manager

Package Overview
Dependencies
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-manager - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

3

History.md

@@ -0,1 +1,4 @@

- 2.4.0 2017-01-17
- Added ability to use a dynamic cache ttl (#65) - @philippeauriach
- 2.3.0 2016-12-22

@@ -2,0 +5,0 @@ - Updating isCacheableValue description in README; README syntax error fix (#70, #71) - @lukechilds

@@ -116,2 +116,6 @@ /** @module cacheManager/caching */

if (options && typeof options.ttl === 'function') {
options.ttl = options.ttl(data);
}
self.store.set(key, data, options, function(err) {

@@ -118,0 +122,0 @@ if (err && (!self.ignoreCacheErrors)) {

2

package.json
{
"name": "cache-manager",
"version": "2.3.0",
"version": "2.4.0",
"description": "Cache module for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -155,2 +155,22 @@ [![build status](https://secure.travis-ci.org/BryanDonovan/node-cache-manager.svg)](http://travis-ci.org/BryanDonovan/node-cache-manager)

The `ttl` can also be computed dynamicall by passing in a function. E.g.,
```javascript
var opts = {
ttl: function(user) {
if (user.id === 1) {
return 0.1;
} else {
return 0.5;
}
}
};
memoryCache.wrap(key, function(cb) {
getUser(userId, cb);
}, opts, function(err, user) {
console.log(user);
}
```
#### Example Using Promises

@@ -157,0 +177,0 @@

@@ -363,2 +363,29 @@ // TODO: These are really a mix of unit and integration tests.

context("ttl function", function() {
beforeEach(function() {
sinon.spy(memoryStoreStub, 'set');
});
afterEach(function() {
memoryStoreStub.set.restore();
});
it("when a ttl function is passed in", function(done) {
opts = {
ttl: function(widget) {
assert.deepEqual(widget, {name: name});
return 0.2;
}
};
cache.wrap(key, function(cb) {
methods.getWidget(name, cb);
}, opts, function(err, widget) {
checkErr(err);
assert.deepEqual(widget, {name: name});
sinon.assert.calledWith(memoryStoreStub.set, key, {name: name}, {ttl: 0.2});
done();
});
});
});
context("when result is already cached", function() {

@@ -365,0 +392,0 @@ function getCachedWidget(name, cb) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc