cache-manager 3.6.3 → 4.1.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 CHANGED
@@ -1,3 +1,13 @@
1
+ - 4.1.0
2
+ - Support for TTL as third arg in memory store set function (#196). - @ZirionNeft
3
+
4
+ - 4.0.1
5
+ - Fix TTL option bug for memory cache (#194). - @anchan828
6
+
7
+ - 4.0.0
8
+ - Upgrade to lru-cache 7.x (#193). - @orgads
9
+ - This has a breaking change in memoryCache.dump().
10
+
1
11
  - 3.6.3 2022-05-20
2
12
  - Remove import from the code in order to be able to bundle and minify the module (#191) - @ricardomozartlino
3
13
 
@@ -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,13 @@ 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
+ if (options && typeof options === 'number') {
68
+ options = {ttl: options};
69
+ }
70
+
71
+ var ttl = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.ttl;
67
72
 
68
- lruCache.set(key, value, maxAge);
73
+ lruCache.set(key, value, {ttl});
69
74
  if (cb) {
70
75
  process.nextTick(cb.bind(null, null));
71
76
  } else if (self.usePromises) {
@@ -86,9 +91,9 @@ var memoryStore = function(args) {
86
91
  options = args.pop();
87
92
  }
88
93
 
89
- var maxAge = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.maxAge;
94
+ var ttl = (options.ttl || options.ttl === 0) ? options.ttl * 1000 : lruOpts.ttl;
90
95
 
91
- var values = setMultipleKeys(args, maxAge);
96
+ var values = setMultipleKeys(args, ttl);
92
97
 
93
98
  if (cb) {
94
99
  process.nextTick(cb.bind(null, null));
@@ -156,7 +161,7 @@ var memoryStore = function(args) {
156
161
  }
157
162
 
158
163
  args.forEach(function(key) {
159
- lruCache.del(key);
164
+ lruCache.delete(key);
160
165
  });
161
166
 
162
167
  if (cb) {
@@ -167,7 +172,7 @@ var memoryStore = function(args) {
167
172
  };
168
173
 
169
174
  self.reset = function(cb) {
170
- lruCache.reset();
175
+ lruCache.clear();
171
176
  if (cb) {
172
177
  process.nextTick(cb.bind(null, null));
173
178
  } else if (self.usePromises) {
@@ -176,7 +181,7 @@ var memoryStore = function(args) {
176
181
  };
177
182
 
178
183
  self.keys = function(cb) {
179
- var keys = lruCache.keys();
184
+ var keys = [...lruCache.keys()];
180
185
  if (cb) {
181
186
  process.nextTick(cb.bind(null, null, keys));
182
187
  } else if (self.usePromises) {
@@ -190,7 +195,7 @@ var memoryStore = function(args) {
190
195
  * This method is not available in the caching modules.
191
196
  */
192
197
  self.keyCount = function() {
193
- return lruCache.length;
198
+ return lruCache.size;
194
199
  };
195
200
 
196
201
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cache-manager",
3
- "version": "3.6.3",
3
+ "version": "4.1.0",
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",