cache-manager 4.0.1 → 5.0.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/History.md DELETED
@@ -1,259 +0,0 @@
1
- - 4.0.1
2
- - Fix TTL option bug for memory cache (#194). - @anchan828
3
-
4
- - 4.0.0
5
- - Upgrade to lru-cache 7.x (#193). - @orgads
6
- - This has a breaking change in memoryCache.dump().
7
-
8
- - 3.6.3 2022-05-20
9
- - Remove import from the code in order to be able to bundle and minify the module (#191) - @ricardomozartlino
10
-
11
- - 3.6.2 2022-05-19
12
- - Use lodash.cloneDeep npm instead of full lodash. (#190). - @ricardomozartlino
13
-
14
- - 3.6.1 2022-04-07
15
- - Fix for potential prototype polution exploit in async < 3.2.2 (#186). - @tmbobbins
16
-
17
- - 3.6.0 2021-11-12
18
- - Added keyCount() method to memory store (#173). - @css-master
19
-
20
- - 3.5.0 2021-11-11
21
- - Added dump() and load() methods to memory store (#171). - @jeoy
22
-
23
- - 3.4.4 2021-06-11
24
- - vulnerability fix in package-lock.json.
25
-
26
- - 3.4.3 2021-03-30
27
- - Bump y18n in package-lock.json (vulnerability fix).
28
-
29
- - 3.4.2 2021-03-29
30
- - Catch uncaught exception to pass it to callback (#154) - @lchenay
31
-
32
- - 3.4.1 2021-03-05
33
- - Update lodash to fix vulnerability (#152).
34
-
35
- - 3.4.0 2020-04-30
36
- - Update dependencies (#145). - @orgads
37
-
38
- - 3.3.0 2020-04-30
39
- - Use full lodash lib instead of lodash.clonedeep npm (#141)
40
-
41
- - 3.2.1 2020-03-20
42
- - Background refresh fixes (#139). -@marcoreni
43
-
44
- - 3.2.0 2020-03-13
45
- - Background refresh of expiring entries (#138). - @marcoreni
46
-
47
- - 3.1.0 2020-02-24
48
- - Pass updateAgeOnGet to lru-cache in memory-store (#136). - @BastianKubaile
49
-
50
- - 3.0.0 2020-02-21
51
- - Added way to disable cloning of values in memory store (#135).
52
-
53
- - 2.11.1 2020-02-03
54
- - Bugfix: Preserve function prototypes in memory store (#133). - @ryanbecker
55
-
56
- - 2.11.0 2020-01-31
57
- - Use eslint instead of jshint/jscs; use nyc instead of istanbul; mocha/coveralls upgrades.
58
-
59
- - 2.10.3 2020-01-31
60
- - Preserve functions in memory store when cloning objects (#132).
61
-
62
- - 2.10.2 2020-01-30
63
- - Disallow mutation of values in memory store (#103).
64
-
65
- - 2.10.1 2019-11-06
66
- - Add .js to module path to fix compilers (#131). - @imjohnbo
67
-
68
- - 2.10.0 2019-07-11
69
- - Add development store "none" (#129). -@R3VoLuT1OneR
70
-
71
- - 2.9.1 2019-05-28
72
- - Bind isCacheableValue to its underlying store (#126). - @arash16
73
-
74
- - 2.9.0 2018-03-26
75
- - Fix store's this context for isCacheableValue method (#119). - @alexandrusavin
76
-
77
- - 2.8.0 2018-02-28
78
- - Added link to node-cache-manager-fs-hash - @rolandstarke
79
- - Bugfix for options object in multiCache.set (#115) - @sebelga
80
- - Bugfix for keysToFetch in getFromHighestProrityCache (#117) - @sebelga
81
-
82
- - 2.7.0 2018-02-13
83
- - allow setting, getting and deleting multiple keys (#114) - @sebelga
84
- - allow passing in a function to determine TTL based on store - @sebelga
85
-
86
- - 2.6.0 2017-12-08
87
- - fix multicaching when result is not cacheable (#106) - @gswalden
88
-
89
- - 2.5.0 2017-10-09
90
- - Add explicit return in wrapPromise (#109) - @jeff-kilbride
91
-
92
- - 2.4.0 2017-01-17
93
- - Added ability to use a dynamic cache ttl (#65) - @philippeauriach
94
-
95
- - 2.3.0 2016-12-22
96
- - Updating isCacheableValue description in README; README syntax error fix (#70, #71) - @lukechilds
97
- - Calling back with null as first argument in memory store to keep style consistent (#72) - @defcc
98
-
99
- - 2.2.0 2016-10-19
100
- - Adding multi_caching.reset() (#63) - @disjunction
101
-
102
- - 2.1.2 2016-06-08
103
- - Checking that callback array exists before iterating over it (#57).
104
-
105
- - 2.1.1 2016-05-24
106
- - Fixing version number in package.json.
107
-
108
- - 2.1.0 2016-05-24
109
- - Allow passing in a promise dependency (#55). - @siddharthkchatterjee
110
-
111
- - 2.0.1 2016-04-18
112
- - Fixed triggering callback in wrap after it was queued (#48) - @theorm
113
-
114
- - 2.0.0 2016-03-13
115
- - Removing domain integration (#38), no longer actively supporting node 0.10.x.
116
-
117
- - 1.5.0 2016-03-13
118
- - npm bumps, making sure global.Promise is not defined in node 0.10 memory store test.
119
-
120
- - 1.4.1 2016-03-13
121
- - Fixing backward-compatibility Promise issue with node 0.10.x in memory store.
122
-
123
- - 1.4.0 2016-02-03
124
- - Passing ttl of 0 to lruCache, upgrading to lru-cache 4.0.0
125
-
126
- - 1.3.0 2016-01-26
127
- - Promise support (#39, #24) - @PuKoren
128
-
129
- - 1.2.2 2015-10-19
130
- - Bugfix: Fixing domain error issues when error is thrown inside 'work' function (#28).
131
-
132
- - 1.2.1 2015-10-17
133
- - Bugfix: multi-caching: using underlying store's isCacheableValue function when it exists (#34).
134
-
135
- - 1.2.0 2015-10-07
136
- - using `isCacheableValue` in `getFromHighestPriorityCache` and `getAndPassUp` (#32).
137
-
138
- - 1.1.0 2015-07-22
139
- - Allow stores to override isCacheableValue. - @PuKoren
140
- - Allow overriding ttl in memory cache's set function. - @zhudan
141
-
142
- - 1.0.0 2015-05-23
143
- - Added JSDOC generation (`make docs`)
144
- - (Breaking change) By default, cache falsey values like `false`, `0`, and `null`, but not `undefined` (#25).
145
- - Allow users to pass in callback function `isCacheableValue` to specify what to cache.
146
- - (Breaking change) Removed deprecated lower-case `multi_caching` export (use `multiCaching` instead).
147
- - (Breaking change) Removed `multiCaching#get_and_pass_up` (use `getAndPassUp` instead).
148
- - (Breaking change) Cache store methods must accept an `options` param (which can be ignored). Eg.,
149
- `function set(key, val, options, cb) { }`
150
- - (Breaking change) caching/multicaching methods no longer accept a `ttl` param. You must instead pass
151
- in an options object which will be passed to the cache store's `set` method.
152
- - (Breaking change) caching.js no longer accepts a path to cache store. Pass in an object or 'memory' instead.
153
-
154
- - 0.19.0 2015-03-29
155
- - Pass dispose, length & stale options to lru-cache (#22). - @gmaclennan
156
-
157
- - 0.18.0 2015-02-12
158
- - Minor changes and refactorings including:
159
- - converting to camelcase
160
- - hiding queues inside CallbackFiller
161
- - general example updates
162
- - updated redis example to use latest redis npm
163
- - not trying to pass ttl into cache.set() in getAndPassUp() (this didn't
164
- work anyway)
165
-
166
- - 0.17.0 2015-02-05
167
- - Add Additional Options Parameter (#20) - @seanzx85
168
- - Fixing bug with nested calls to wrap() (#21)
169
-
170
- - 0.16.0 2015-01-07
171
- - Get and pass up feature to update higher caches. (#19) - raadad
172
- - Minor style tweaks/jscs update.
173
-
174
- - 0.15.0 2014-12-18
175
- - Moved cache queue before the store get function (up to 2x performance boost). (#18) - aletorrado
176
- - Added domain support to make sure the wrap callback function is always called - aletorrado
177
-
178
- - 0.14.0 2014-10-15
179
- - Set ttl in wrap #14 - nguyenchr
180
- - Added JSCS for style checking
181
-
182
- - 0.13.0 2014-10-14
183
- - Applied work function locking for multi_caching (#13). -aletorrado
184
-
185
- - 0.12.0 2014-10-09
186
- - Checking for existence of del() method before binding to it. Fixes #11.
187
-
188
- - 0.11.0 2014-09-18
189
- - Prevent stalemate by executing callbacks on error. Fixes #10 - elliotttf
190
-
191
- - 0.10.1 2014-09-10
192
- - Fixed tag/version mismatch
193
-
194
- - 0.10.0 2014-09-10
195
- - Fixing Use call instead of apply for cached results, issue #9 (thanks elliotttf)
196
-
197
- - 0.9.0 2014-08-19
198
- - Fixing issue #8 - parallel requests to a wrapped function were calling the
199
- function multiple times. (Thanks alex-whitney).
200
-
201
- - 0.8.0 2014-07-07
202
- - Adding setex() (Thanks evanlucas)
203
-
204
- - 0.7.1 2014-06-15
205
- - Adding link to Express.js cache-manager example app
206
-
207
- - 0.7.0 2014-06-15
208
- - Bumping package versions, mostly devDependencies
209
-
210
- - 0.6.0 2014-06-15
211
- - Adding caching.keys() function (issue #6)
212
- - Updating examples/redis_example/example.js with cache.keys() usage
213
- - Allow calling memory store get() without callback
214
-
215
- - 0.5.0 2014-05-02
216
- - Adding reset() function to caching.js. Closes #5.
217
-
218
- - 0.4.0 2014-05-02
219
- - New arg to ignore cache errors. if set cache errors will be ignored
220
- and the cache_manager will go to the backing store. (Thanks londonjamo).
221
-
222
- - 0.3.0 2013-12-08
223
- - Bound the get, set and del functions to their original “this” context when assigning a store.
224
- (Thanks to Boyan Rabchev)
225
-
226
- - 0.2.0 2013-10-31
227
- - Better examples, version bump.
228
-
229
- - 0.1.3 2013-10-31
230
- - Fixing unreleased connection in redis example.
231
-
232
- - 0.1.2 2013-10-13
233
- - Wrapping synchronous memory cache callbacks in process.nextTick() for the purists.
234
-
235
- - 0.1.1 2013-10-13
236
- - Travis and Coveralls integration testing.
237
-
238
- - 0.1.0 2013-10-13
239
- - Removing built-in Redis store to emphasize that you should plug in your own
240
- cache store.
241
-
242
- - 0.0.5 2013-10-13
243
- - Removing hiredis requirement.
244
-
245
- - 0.0.4 2013-08-01
246
- - Better error checking in multi_cache.wrap();
247
-
248
- - 0.0.3 2013-07-10
249
- - Better error checking in cache.wrap();
250
-
251
- - 0.0.2 2013-04-08
252
- - Added ability to pass in a store module that isn't already instantiated. E.g.,
253
-
254
- ```javascript
255
- var store = require('/path/to/my_memory_store');
256
- cache = caching({store: store});
257
- ```
258
- - 0.0.1 2013-04-08
259
- - Initial release.
@@ -1,133 +0,0 @@
1
- /*jshint unused:false*/
2
- // Note: ttls are in seconds
3
- var cacheManager = require('../');
4
- var memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10});
5
- var memoryCache2 = cacheManager.caching({store: 'memory', max: 100, ttl: 100});
6
-
7
- //
8
- // Basic usage
9
- //
10
- memoryCache.set('foo', 'bar', function(err) {
11
- if (err) { throw err; }
12
-
13
- memoryCache.get('foo', function(err, result) {
14
- console.log(result);
15
- // >> 'bar'
16
- memoryCache.del('foo', function(err) {
17
- if (err) {
18
- console.log(err);
19
- }
20
- });
21
- });
22
- });
23
-
24
- function getUser(id, cb) {
25
- setTimeout(function() {
26
- console.log("Fetching user from slow database.");
27
- cb(null, {id: id, name: 'Bob'});
28
- }, 100);
29
- }
30
-
31
- var userId = 123;
32
- var key = 'user_' + userId;
33
-
34
- //
35
- // wrap() example
36
- //
37
-
38
- /**
39
- Instead of manually managing the cache like this:
40
- function getCachedUserManually(id, cb) {
41
- memoryCache.get(id, function(err, result) {
42
- if (err) { return cb(err); }
43
-
44
- if (result) {
45
- return cb(null, result);
46
- }
47
-
48
- getUser(id, function(err, result) {
49
- if (err) { return cb(err); }
50
- memoryCache.set(id, result);
51
- cb(null, result);
52
- });
53
- });
54
- }
55
- */
56
-
57
- // ... you can instead use the `wrap` function:
58
- function getCachedUser(id, cb) {
59
- memoryCache.wrap(id, function(cacheCallback) {
60
- getUser(id, cacheCallback);
61
- }, cb);
62
- }
63
-
64
- getCachedUser(userId, function(err, user) {
65
- // First time fetches the user from the (fake) database:
66
- console.log(user);
67
-
68
- getCachedUser(userId, function(err, user) {
69
- // Second time fetches from cache.
70
- console.log(user);
71
- });
72
- });
73
-
74
- // Outputs:
75
- // Returning user from slow database.
76
- // { id: 123, name: 'Bob' }
77
- // { id: 123, name: 'Bob' }
78
-
79
- // Same as above, but written differently:
80
- memoryCache.wrap(key, function(cb) {
81
- getUser(userId, cb);
82
- }, function(err, user) {
83
- console.log(user);
84
-
85
- // Second time fetches user from memoryCache
86
- memoryCache.wrap(key, function(cb) {
87
- getUser(userId, cb);
88
- }, function(err, user) {
89
- console.log(user);
90
- });
91
- });
92
-
93
- //
94
- // multi-cache example
95
- //
96
- var multiCache = cacheManager.multiCaching([memoryCache, memoryCache2]);
97
- var userId2 = 456;
98
- var key2 = 'user_' + userId;
99
- var ttl2; //Can't use a different ttl per set() call with memory cache
100
-
101
- multiCache.wrap(key2, function(cb) {
102
- getUser(userId2, cb);
103
- }, function(err, user) {
104
- console.log(user);
105
-
106
- // Second time fetches user from memoryCache, since it's highest priority.
107
- // If the data expires in memoryCache, the next fetch would pull it from
108
- // the memoryCache2, and set the data in memoryCache.
109
- multiCache.wrap(key2, function(cb) {
110
- getUser(userId2, cb);
111
- }, function(err, user) {
112
- console.log(user);
113
- });
114
-
115
- // Sets in all caches.
116
- multiCache.set('foo2', 'bar2', {ttl: ttl2}, function(err) {
117
- if (err) { throw err; }
118
-
119
- // Fetches from highest priority cache that has the key.
120
- multiCache.get('foo2', function(err, result) {
121
- console.log(result);
122
- // >> 'bar2'
123
-
124
- // Delete from all caches
125
- multiCache.del('foo2', function(err) {
126
- if (err) {
127
- console.log(err);
128
- }
129
- process.exit();
130
- });
131
- });
132
- });
133
- });
@@ -1,147 +0,0 @@
1
- // Setup:
2
- // npm install redis@0.12.1 sol-redis-pool@0.2.0
3
- // node examples/redis_example/example.js
4
-
5
- var util = require('util');
6
- var assert = require('assert');
7
- var cacheManager = require('../../');
8
- var redisStore = require('./redis_store');
9
- // Note: ttl is in seconds
10
- var redisCache = cacheManager.caching({store: redisStore, db: 0, ttl: 100});
11
- var ttl = 60;
12
-
13
- console.log("set/get/del example:");
14
-
15
- redisCache.set('foo', 'bar', {ttl: ttl}, function(err) {
16
- if (err) { throw err; }
17
-
18
- redisCache.get('foo', function(err, result) {
19
- if (err) { throw err; }
20
- console.log("result fetched from cache: " + result);
21
- // >> 'bar'
22
-
23
- redisCache.ttl('foo', function(err, result) {
24
- if (err) { throw err; }
25
- assert.ok(result > 59 && result < 61);
26
-
27
- redisCache.del('foo', function(err) {
28
- if (err) { throw err; }
29
- });
30
- });
31
- });
32
- });
33
-
34
- // TTL defaults to what we passed into the caching function (100)
35
- redisCache.set('foo-no-ttl', 'bar-no-ttl', function(err) {
36
- if (err) { throw err; }
37
-
38
- redisCache.get('foo-no-ttl', function(err, result) {
39
- if (err) { throw err; }
40
- console.log("result fetched from cache: " + result);
41
- // >> 'bar'
42
-
43
- redisCache.ttl('foo-no-ttl', function(err, result) {
44
- if (err) { throw err; }
45
- assert.ok(result > 99 && result < 101);
46
-
47
- redisCache.del('foo-no-ttl', function(err) {
48
- if (err) { throw err; }
49
- });
50
- });
51
- });
52
- });
53
-
54
- // Calls Redis 'set' instead of 'setex'
55
- redisCache.set('foo-zero-ttl', 'bar-zero-ttl', {ttl: 0}, function(err) {
56
- if (err) { throw err; }
57
-
58
- redisCache.get('foo-zero-ttl', function(err, result) {
59
- if (err) { throw err; }
60
- console.log("result fetched from cache: " + result);
61
- // >> 'bar'
62
-
63
- redisCache.ttl('foo-zero-ttl', function(err, result) {
64
- if (err) { throw err; }
65
- assert.ok(result < 0);
66
-
67
- redisCache.del('foo-zero-ttl', function(err) {
68
- if (err) { throw err; }
69
- });
70
- });
71
- });
72
- });
73
-
74
- var userId = 123;
75
-
76
- function createKey(id) {
77
- return 'user_' + id;
78
- }
79
-
80
- function getUser(id, cb) {
81
- setTimeout(function() {
82
- console.log("\n\nReturning user from slow database.");
83
- cb(null, {id: id, name: 'Bob'});
84
- }, 100);
85
- }
86
-
87
- function getUserFromCache(id, cb) {
88
- var key = createKey(id);
89
- redisCache.wrap(key, function(cacheCb) {
90
- getUser(userId, cacheCb);
91
- }, {ttl: ttl}, cb);
92
- }
93
-
94
- getUserFromCache(userId, function(err, user) {
95
- console.log(user);
96
-
97
- // Second time fetches user from redisCache
98
- getUserFromCache(userId, function(err, user) {
99
- console.log("user from second cache request:");
100
- console.log(user);
101
-
102
- redisCache.keys(function(err, keys) {
103
- console.log("keys: " + util.inspect(keys));
104
-
105
- var key = createKey(userId);
106
- redisCache.del(key, function(err) {
107
- if (err) { throw err; }
108
- });
109
- });
110
- });
111
- });
112
-
113
- // Outputs:
114
- // { id: 123, name: 'Bob' }
115
- // user from second cache request:
116
- // { id: 123, name: 'Bob' }
117
- // keys: [ 'user_123' ]
118
-
119
- var redisCache2 = cacheManager.caching({store: redisStore, db: 1, ttl: 100});
120
- var multiCache = cacheManager.multiCaching([redisCache, redisCache2]);
121
- var userId2 = 456;
122
- var key2 = 'user_' + userId;
123
- var ttl2 = 50;
124
-
125
- multiCache.wrap(key2, function(cb) {
126
- getUser(userId2, cb);
127
- }, {ttl: ttl2}, function(err, user) {
128
- console.log("user: ", user);
129
-
130
- // Second time fetches user from redisCache, since it's highest priority.
131
- // If the data expires in the redisCache, the next fetch would pull it from
132
- // redisCache2, and set the data in redisCache again.
133
- multiCache.wrap(key2, function(cb) {
134
- getUser(userId2, cb);
135
- }, function(err, user) {
136
- console.log("user, second fetch:", user);
137
- });
138
-
139
- multiCache.getAndPassUp(key2, function(err, result) {
140
- console.log("\ngetAndPassUp result: ", result);
141
-
142
- multiCache.del(key2, function(err) {
143
- if (err) { throw err; }
144
- process.exit();
145
- });
146
- });
147
- });
@@ -1,124 +0,0 @@
1
- /**
2
- * This is a very basic example of how you can implement your own Redis-based
3
- * cache store with connection pooling.
4
- */
5
-
6
- var RedisPool = require('sol-redis-pool');
7
-
8
- function redisStore(args) {
9
- args = args || {};
10
- var self = {};
11
- var ttlDefault = args.ttl;
12
- self.name = 'redis';
13
-
14
- var redisOptions = {
15
- host: args.host || '127.0.0.1',
16
- port: args.port || 6379
17
- };
18
-
19
- var pool = new RedisPool(redisOptions, {});
20
-
21
- function connect(cb) {
22
- pool.acquire(function(err, conn) {
23
- if (err) {
24
- pool.release(conn);
25
- return cb(err);
26
- }
27
-
28
- if (args.db || args.db === 0) {
29
- conn.select(args.db);
30
- }
31
-
32
- cb(null, conn);
33
- });
34
- }
35
-
36
- function handleResponse(conn, cb, opts) {
37
- opts = opts || {};
38
-
39
- return function(err, result) {
40
- pool.release(conn);
41
-
42
- if (err) { return cb(err); }
43
-
44
- if (opts.parse) {
45
- result = JSON.parse(result);
46
- }
47
-
48
- cb(null, result);
49
- };
50
- }
51
-
52
- self.get = function(key, options, cb) {
53
- if (typeof options === 'function') {
54
- cb = options;
55
- }
56
-
57
- connect(function(err, conn) {
58
- if (err) { return cb(err); }
59
- conn.get(key, handleResponse(conn, cb, {parse: true}));
60
- });
61
- };
62
-
63
- self.set = function(key, value, options, cb) {
64
- if (typeof options === 'function') {
65
- cb = options;
66
- options = {};
67
- }
68
- options = options || {};
69
-
70
- var ttl = (options.ttl || options.ttl === 0) ? options.ttl : ttlDefault;
71
-
72
- connect(function(err, conn) {
73
- if (err) { return cb(err); }
74
- var val = JSON.stringify(value);
75
-
76
- if (ttl) {
77
- conn.setex(key, ttl, val, handleResponse(conn, cb));
78
- } else {
79
- conn.set(key, val, handleResponse(conn, cb));
80
- }
81
- });
82
- };
83
-
84
- self.del = function(key, options, cb) {
85
- if (typeof options === 'function') {
86
- cb = options;
87
- }
88
- connect(function(err, conn) {
89
- if (err) { return cb(err); }
90
- conn.del(key, handleResponse(conn, cb));
91
- });
92
- };
93
-
94
- self.ttl = function(key, cb) {
95
- connect(function(err, conn) {
96
- if (err) { return cb(err); }
97
- conn.ttl(key, handleResponse(conn, cb));
98
- });
99
- };
100
-
101
- self.keys = function(pattern, cb) {
102
- if (typeof pattern === 'function') {
103
- cb = pattern;
104
- pattern = '*';
105
- }
106
-
107
- connect(function(err, conn) {
108
- if (err) { return cb(err); }
109
- conn.keys(pattern, handleResponse(conn, cb));
110
- });
111
- };
112
-
113
- self.isCacheableValue = function(value) {
114
- return value !== null && value !== undefined;
115
- };
116
-
117
- return self;
118
- }
119
-
120
- module.exports = {
121
- create: function(args) {
122
- return redisStore(args);
123
- }
124
- };
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./lib');