cache-manager 2.5.0 → 2.9.0
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/.npmignore +1 -0
- package/History.md +15 -0
- package/README.md +101 -3
- package/lib/caching.js +147 -21
- package/lib/multi_caching.js +355 -68
- package/lib/stores/memory.js +80 -4
- package/lib/utils.js +43 -0
- package/package.json +2 -2
- package/test/caching.unit.js +333 -2
- package/test/multi_caching.unit.js +589 -5
- package/test/utils.unit.js +25 -0
- package/config.js +0 -7
- package/test/foo.unit.js +0 -69
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
var utils = require('../lib/utils');
|
|
3
|
+
var assert = require('assert');
|
|
4
|
+
|
|
5
|
+
var isObject = utils.isObject;
|
|
6
|
+
|
|
7
|
+
describe('utils', function() {
|
|
8
|
+
describe('isObject()', function() {
|
|
9
|
+
it('should return "true" when value passed is an object', function() {
|
|
10
|
+
var result1 = isObject({});
|
|
11
|
+
assert.ok(result1);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should return "false" when value passed is not an object', function() {
|
|
15
|
+
var result1 = isObject('string');
|
|
16
|
+
var result2 = isObject(123);
|
|
17
|
+
var result3 = isObject([]);
|
|
18
|
+
var result4 = isObject(function() {});
|
|
19
|
+
assert.ok(!result1);
|
|
20
|
+
assert.ok(!result2);
|
|
21
|
+
assert.ok(!result3);
|
|
22
|
+
assert.ok(!result4);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
package/config.js
DELETED
package/test/foo.unit.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/*jshint esversion:6*/
|
|
3
|
-
const manager = require('..');
|
|
4
|
-
|
|
5
|
-
let cache = manager.multiCaching([
|
|
6
|
-
manager.caching({
|
|
7
|
-
ttl: 3000,
|
|
8
|
-
store: 'memory',
|
|
9
|
-
}),
|
|
10
|
-
manager.caching({
|
|
11
|
-
ttl: 3000,
|
|
12
|
-
store: 'memory',
|
|
13
|
-
})],
|
|
14
|
-
{
|
|
15
|
-
isCacheableValue: value => {
|
|
16
|
-
console.log("\nHERE:");
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const key1 = 'key1';
|
|
23
|
-
const key2 = 'key2';
|
|
24
|
-
|
|
25
|
-
const getData = fn => setTimeout(() => fn(null, 'SOME_DATA'), 1000);
|
|
26
|
-
const getEmpty = fn => setTimeout(() => fn(null), 1000);
|
|
27
|
-
|
|
28
|
-
/*
|
|
29
|
-
cache.wrap(key2, getData, (err, data) => {
|
|
30
|
-
console.log(`RETURN FROM WRAP WITH DATA ${key1} (1)`, err, data);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
cache.wrap(key2, getData, (err, data) => {
|
|
34
|
-
console.log(`RETURN FROM WRAP WITH DATA ${key2} (2)`, err, data);
|
|
35
|
-
});
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
cache.wrap(key1, getEmpty, (err, data) => {
|
|
39
|
-
console.log(`RETURN FROM (multi) WRAP WITHOUT DATA ${key1} (1)`, err, data);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
cache.wrap(key1, getEmpty, (err, data) => {
|
|
43
|
-
console.log(`RETURN FROM (multi) WRAP WITHOUT DATA ${key1} (2)`, err, data);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
console.log("NEXT...");
|
|
47
|
-
|
|
48
|
-
cache = manager.caching({
|
|
49
|
-
ttl: 3000,
|
|
50
|
-
store: 'memory',
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
/*
|
|
54
|
-
cache.wrap(key2, getData, (err, data) => {
|
|
55
|
-
console.log(`RETURN FROM WRAP WITH DATA ${key1} (1)`, err, data);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
cache.wrap(key2, getData, (err, data) => {
|
|
59
|
-
console.log(`RETURN FROM WRAP WITH DATA ${key2} (2)`, err, data);
|
|
60
|
-
});
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
cache.wrap(key1, getEmpty, (err, data) => {
|
|
64
|
-
console.log(`RETURN FROM WRAP WITHOUT DATA ${key1} (1)`, err, data);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
cache.wrap(key1, getEmpty, (err, data) => {
|
|
68
|
-
console.log(`RETURN FROM WRAP WITHOUT DATA ${key1} (2)`, err, data);
|
|
69
|
-
});
|