cache-manager 3.6.2 → 4.0.1

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 CHANGED
@@ -1,3 +1,13 @@
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
+
1
11
  - 3.6.2 2022-05-19
2
12
  - Use lodash.cloneDeep npm instead of full lodash. (#190). - @ricardomozartlino
3
13
 
package/lib/caching.js CHANGED
@@ -2,8 +2,12 @@
2
2
  /*jshint maxcomplexity:16*/
3
3
  var CallbackFiller = require('./callback_filler');
4
4
  var utils = require('./utils');
5
+ var memory = require('./stores/memory.js');
6
+ var none = require('./stores/none.js');
5
7
  var parseWrapArguments = utils.parseWrapArguments;
6
8
 
9
+ var bundledStores = {memory, none};
10
+
7
11
  /**
8
12
  * Generic caching interface that wraps any caching library with a compatible interface.
9
13
  *
@@ -25,7 +29,7 @@ var caching = function(args) {
25
29
  }
26
30
  } else {
27
31
  var storeName = args.store || 'memory';
28
- self.store = require('./stores/' + storeName + '.js').create(args);
32
+ self.store = bundledStores[storeName].create(args);
29
33
  }
30
34
 
31
35
  // do we handle a cache error the same as a cache miss?
@@ -30,23 +30,24 @@ var memoryStore = function(args) {
30
30
  self.usePromises = !(typeof Promise === 'undefined' || args.noPromises);
31
31
  self.shouldCloneBeforeSet = args.shouldCloneBeforeSet !== false; // clone by default
32
32
 
33
- var ttl = args.ttl;
34
33
  var lruOpts = {
35
34
  max: args.max || 500,
36
- maxAge: (ttl || ttl === 0) ? ttl * 1000 : null,
35
+ maxSize: args.maxSize,
36
+ ttl: (args.ttl || args.ttl === 0) ? args.ttl * 1000 : undefined,
37
37
  dispose: args.dispose,
38
- length: args.length,
39
- stale: args.stale,
40
- updateAgeOnGet: args.updateAgeOnGet || false
38
+ sizeCalculation: args.sizeCalculation || args.length,
39
+ allowStale: args.allowStale || args.stale,
40
+ updateAgeOnGet: args.updateAgeOnGet,
41
+ updateAgeOnHas: args.updateAgeOnHas
41
42
  };
42
43
 
43
44
  var lruCache = new Lru(lruOpts);
44
45
 
45
- var setMultipleKeys = function setMultipleKeys(keysValues, maxAge) {
46
+ var setMultipleKeys = function setMultipleKeys(keysValues, ttl) {
46
47
  var length = keysValues.length;
47
48
  var values = [];
48
49
  for (var i = 0; i < length; i += 2) {
49
- lruCache.set(keysValues[i], keysValues[i + 1], maxAge);
50
+ lruCache.set(keysValues[i], keysValues[i + 1], {ttl});
50
51
  values.push(keysValues[i + 1]);
51
52
  }
52
53
  return values;
@@ -63,9 +64,9 @@ var memoryStore = function(args) {
63
64
  }
64
65
  options = options || {};
65
66
 
66
- var maxAge = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.maxAge;
67
+ var ttl = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.ttl;
67
68
 
68
- lruCache.set(key, value, maxAge);
69
+ lruCache.set(key, value, {ttl});
69
70
  if (cb) {
70
71
  process.nextTick(cb.bind(null, null));
71
72
  } else if (self.usePromises) {
@@ -86,9 +87,9 @@ var memoryStore = function(args) {
86
87
  options = args.pop();
87
88
  }
88
89
 
89
- var maxAge = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.maxAge;
90
+ var ttl = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.ttl;
90
91
 
91
- var values = setMultipleKeys(args, maxAge);
92
+ var values = setMultipleKeys(args, ttl);
92
93
 
93
94
  if (cb) {
94
95
  process.nextTick(cb.bind(null, null));
@@ -156,7 +157,7 @@ var memoryStore = function(args) {
156
157
  }
157
158
 
158
159
  args.forEach(function(key) {
159
- lruCache.del(key);
160
+ lruCache.delete(key);
160
161
  });
161
162
 
162
163
  if (cb) {
@@ -167,7 +168,7 @@ var memoryStore = function(args) {
167
168
  };
168
169
 
169
170
  self.reset = function(cb) {
170
- lruCache.reset();
171
+ lruCache.clear();
171
172
  if (cb) {
172
173
  process.nextTick(cb.bind(null, null));
173
174
  } else if (self.usePromises) {
@@ -176,7 +177,7 @@ var memoryStore = function(args) {
176
177
  };
177
178
 
178
179
  self.keys = function(cb) {
179
- var keys = lruCache.keys();
180
+ var keys = [...lruCache.keys()];
180
181
  if (cb) {
181
182
  process.nextTick(cb.bind(null, null, keys));
182
183
  } else if (self.usePromises) {
@@ -190,7 +191,7 @@ var memoryStore = function(args) {
190
191
  * This method is not available in the caching modules.
191
192
  */
192
193
  self.keyCount = function() {
193
- return lruCache.length;
194
+ return lruCache.size;
194
195
  };
195
196
 
196
197
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cache-manager",
3
- "version": "3.6.2",
3
+ "version": "4.0.1",
4
4
  "description": "Cache module for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "async": "3.2.3",
29
29
  "lodash.clonedeep": "^4.5.0",
30
- "lru-cache": "6.0.0"
30
+ "lru-cache": "^7.10.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "coveralls": "3.1.0",