cache-manager 2.10.1 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +1 -1
- package/History.md +3 -0
- package/lib/stores/memory.js +3 -0
- package/package.json +2 -1
- package/test/multi_caching.unit.js +3 -3
- package/test/stores/memory.unit.js +94 -0
package/.travis.yml
CHANGED
package/History.md
CHANGED
package/lib/stores/memory.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
var Lru = require("lru-cache");
|
|
2
|
+
var cloneDeep = require('lodash.clonedeep');
|
|
2
3
|
var utils = require('../utils');
|
|
3
4
|
var isObject = utils.isObject;
|
|
4
5
|
|
|
@@ -31,6 +32,8 @@ var memoryStore = function(args) {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
self.set = function(key, value, options, cb) {
|
|
35
|
+
value = cloneDeep(value);
|
|
36
|
+
|
|
34
37
|
if (typeof options === 'function') {
|
|
35
38
|
cb = options;
|
|
36
39
|
options = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cache-manager",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.2",
|
|
4
4
|
"description": "Cache module for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"async": "1.5.2",
|
|
24
|
+
"lodash.clonedeep": "4.5.0",
|
|
24
25
|
"lru-cache": "4.0.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
@@ -96,15 +96,15 @@ describe("multiCaching", function() {
|
|
|
96
96
|
|
|
97
97
|
memoryCache.get(key, function(err, result) {
|
|
98
98
|
checkErr(err);
|
|
99
|
-
assert.
|
|
99
|
+
assert.deepEqual(result, value);
|
|
100
100
|
|
|
101
101
|
memoryCache2.get(key, function(err, result) {
|
|
102
102
|
checkErr(err);
|
|
103
|
-
assert.
|
|
103
|
+
assert.deepEqual(result, value);
|
|
104
104
|
|
|
105
105
|
memoryCache3.get(key, function(err, result) {
|
|
106
106
|
checkErr(err);
|
|
107
|
-
assert.
|
|
107
|
+
assert.deepEqual(result, value);
|
|
108
108
|
done();
|
|
109
109
|
});
|
|
110
110
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
2
|
var support = require('../support');
|
|
3
|
+
var checkErr = support.checkErr;
|
|
4
|
+
var caching = require('../../index').caching;
|
|
3
5
|
var memoryStore = require('../../lib/stores/memory');
|
|
4
6
|
|
|
5
7
|
describe("memory store", function() {
|
|
@@ -34,4 +36,96 @@ describe("memory store", function() {
|
|
|
34
36
|
}, 10);
|
|
35
37
|
});
|
|
36
38
|
});
|
|
39
|
+
|
|
40
|
+
describe("when used with wrap() function", function() {
|
|
41
|
+
var cache;
|
|
42
|
+
var key;
|
|
43
|
+
var opts = {};
|
|
44
|
+
|
|
45
|
+
beforeEach(function() {
|
|
46
|
+
key = support.random.string(20);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
context("when cache misses", function() {
|
|
50
|
+
function getCachedObject(name, cb) {
|
|
51
|
+
cache.wrap(key, function(cacheCb) {
|
|
52
|
+
cacheCb(null, {foo: 'bar'});
|
|
53
|
+
}, opts, cb);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getCachedString(name, cb) {
|
|
57
|
+
cache.wrap(key, function(cacheCb) {
|
|
58
|
+
cacheCb(null, 'bar');
|
|
59
|
+
}, opts, cb);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getCachedArray(name, cb) {
|
|
63
|
+
cache.wrap(key, function(cacheCb) {
|
|
64
|
+
cacheCb(null, [1, 2, 3]);
|
|
65
|
+
}, opts, cb);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getCachedNumber(name, cb) {
|
|
69
|
+
cache.wrap(key, function(cacheCb) {
|
|
70
|
+
cacheCb(null, 34);
|
|
71
|
+
}, opts, cb);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
beforeEach(function() {
|
|
75
|
+
cache = caching({store: 'memory', safeClone: true, ttl: opts.ttl, ignoreCacheErrors: false});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("does not allow mutation of objects", function(done) {
|
|
79
|
+
getCachedObject('foo', function(err, result) {
|
|
80
|
+
checkErr(err);
|
|
81
|
+
result.foo = 'buzz';
|
|
82
|
+
|
|
83
|
+
getCachedObject('foo', function(err, result) {
|
|
84
|
+
checkErr(err);
|
|
85
|
+
assert.equal(result.foo, 'bar');
|
|
86
|
+
done();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("does not allow mutation of arrays", function(done) {
|
|
92
|
+
getCachedArray('foo', function(err, result) {
|
|
93
|
+
checkErr(err);
|
|
94
|
+
result = ['a', 'b', 'c'];
|
|
95
|
+
|
|
96
|
+
getCachedArray('foo', function(err, result) {
|
|
97
|
+
checkErr(err);
|
|
98
|
+
assert.deepEqual(result, [1, 2, 3]);
|
|
99
|
+
done();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("does not allow mutation of strings", function(done) {
|
|
105
|
+
getCachedString('foo', function(err, result) {
|
|
106
|
+
checkErr(err);
|
|
107
|
+
result = 'buzz';
|
|
108
|
+
|
|
109
|
+
getCachedString('foo', function(err, result) {
|
|
110
|
+
checkErr(err);
|
|
111
|
+
assert.equal(result, 'bar');
|
|
112
|
+
done();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("does not allow mutation of numbers", function(done) {
|
|
118
|
+
getCachedNumber('foo', function(err, result) {
|
|
119
|
+
checkErr(err);
|
|
120
|
+
result = 12;
|
|
121
|
+
|
|
122
|
+
getCachedNumber('foo', function(err, result) {
|
|
123
|
+
checkErr(err);
|
|
124
|
+
assert.equal(result, 34);
|
|
125
|
+
done();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
37
131
|
});
|