cache-manager
Advanced tools
Comparing version 2.10.0 to 2.10.1
@@ -0,3 +1,6 @@ | ||
- 2.10.1 2019-11-06 | ||
- Add .js to module path to fix compilers (#131). -@imjohnbo | ||
- 2.10.0 2019-07-11 | ||
- Add development store "none" (#129). -@ R3VoLuT1OneR | ||
- Add development store "none" (#129). -@R3VoLuT1OneR | ||
@@ -4,0 +7,0 @@ - 2.9.1 2019-05-28 |
@@ -28,3 +28,3 @@ /** @module cacheManager/caching */ | ||
var storeName = args.store || 'memory'; | ||
self.store = require('./stores/' + storeName).create(args); | ||
self.store = require('./stores/' + storeName + '.js').create(args); | ||
} | ||
@@ -189,7 +189,7 @@ | ||
*/ | ||
var cacheOK = Array.isArray(result) && result.filter(function(_result) { | ||
var cacheOk = Array.isArray(result) && result.filter(function(_result) { | ||
return self._isCacheableValue(_result); | ||
}).length === result.length; | ||
if (cacheOK) { | ||
if (cacheOk) { | ||
return callbackFiller.fill(combinedKey, null, result); | ||
@@ -199,3 +199,3 @@ } | ||
return work(function(err, data) { | ||
if (err) { | ||
if (err || !data) { | ||
return done(err); | ||
@@ -202,0 +202,0 @@ } |
{ | ||
"name": "cache-manager", | ||
"version": "2.10.0", | ||
"version": "2.10.1", | ||
"description": "Cache module for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -187,4 +187,17 @@ [![build status](https://secure.travis-ci.org/BryanDonovan/node-cache-manager.svg)](http://travis-ci.org/BryanDonovan/node-cache-manager) | ||
You can get several keys at once. E.g. | ||
You can get several keys at once. Note that this will return whatever records it | ||
finds in the cache and it is up to the user to check the results against the | ||
supplied keys and make any calls to the underlying data store to fill in | ||
missing records. In practice, this should not be much of a concern if you are | ||
only using the `wrap` function to set these records in cache. | ||
Side note: Ideally the `wrap` function would get what it can from the cache and fill in | ||
the missing records from the data store, but I can't think of a way to do this | ||
that is generic to all situations. Another option is to only return the data | ||
from the cache if all records are found, but this woul break multi-caching. | ||
See unit tests in `caching.unit.js` for more information. | ||
Example: | ||
```js | ||
@@ -191,0 +204,0 @@ |
@@ -909,4 +909,4 @@ // TODO: These are really a mix of unit and integration tests. | ||
beforeEach(function() { | ||
key2 = support.random.string(20); | ||
name2 = support.random.string(); | ||
key2 = '2-' + support.random.string(20); | ||
name2 = '2-' + support.random.string(); | ||
sinon.spy(memoryStoreStub, 'mset'); | ||
@@ -919,2 +919,26 @@ }); | ||
context("when no keys are already cached", function() { | ||
it("retrieves data from data store and caches results via mset", function(done) { | ||
var funcCalled = false; | ||
sinon.stub(memoryStoreStub, 'mget').yields(); | ||
cache.wrap(key, key2, function(cb) { | ||
funcCalled = true; | ||
cb(null, [{name: name}, {name: name2}]); | ||
}, function(err) { | ||
checkErr(err); | ||
assert.ok(memoryStoreStub.mget.calledWith(key, key2)); | ||
assert.ok(funcCalled); | ||
assert.ok(memoryStoreStub.mset.called); | ||
var callArgs = memoryStoreStub.mset.args[0]; | ||
assert.equal(callArgs[0], key); | ||
assert.deepEqual(callArgs[1], {name: name}); | ||
assert.equal(callArgs[2], key2); | ||
assert.deepEqual(callArgs[3], {name: name2}); | ||
memoryStoreStub.mget.restore(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
context("when result is already cached", function() { | ||
@@ -944,2 +968,27 @@ it("retrieves data from cache", function(done) { | ||
context("when some keys are already cached but others are not", function() { | ||
// This means the user must manually call the data store to get any | ||
// values that are not in cache, which is not ideal. | ||
it("responds with only the data that exists in the cache", function(done) { | ||
var key3 = support.random.string(); | ||
var name3 = support.random.string(); | ||
var funcCalled = false; | ||
sinon.stub(memoryStoreStub, 'mget').yields(null, [{name: name}, {name: name3}]); | ||
cache.wrap(key, key2, key3, function(cb) { | ||
funcCalled = true; | ||
methods.getMultiWidget([name2], cb); | ||
}, function(err, widgets) { | ||
checkErr(err); | ||
assert.deepEqual(widgets[0], {name: name}); | ||
assert.deepEqual(widgets[1], {name: name3}); | ||
assert.ok(memoryStoreStub.mget.calledWith(key, key2)); | ||
assert.ok(!funcCalled); | ||
memoryStoreStub.mget.restore(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it("when a ttl is passed in", function(done) { | ||
@@ -946,0 +995,0 @@ cache.wrap(key, key2, function(cb) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
210173
4480
456