cache-manager 5.6.0 → 5.6.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/dist/caching.js +17 -9
- package/dist/index.js +19 -3
- package/dist/multi-caching.js +10 -3
- package/dist/stores/index.js +17 -1
- package/dist/stores/memory.js +12 -5
- package/package.json +1 -1
package/dist/caching.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCache = exports.caching = void 0;
|
|
7
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
|
+
const promise_coalesce_1 = require("promise-coalesce");
|
|
9
|
+
const index_js_1 = require("./stores/index.js");
|
|
4
10
|
/**
|
|
5
11
|
* Generic caching interface that wraps any caching library with a compatible interface.
|
|
6
12
|
*/
|
|
7
|
-
|
|
13
|
+
async function caching(factory, arguments_) {
|
|
8
14
|
if (factory === 'memory') {
|
|
9
|
-
const store = memoryStore(arguments_);
|
|
15
|
+
const store = (0, index_js_1.memoryStore)(arguments_);
|
|
10
16
|
return createCache(store, arguments_);
|
|
11
17
|
}
|
|
12
18
|
if (typeof factory === 'function') {
|
|
@@ -16,11 +22,12 @@ export async function caching(factory, arguments_) {
|
|
|
16
22
|
const store = factory;
|
|
17
23
|
return createCache(store, arguments_);
|
|
18
24
|
}
|
|
25
|
+
exports.caching = caching;
|
|
19
26
|
/**
|
|
20
27
|
* Create cache instance by store (non-async).
|
|
21
28
|
*/
|
|
22
|
-
|
|
23
|
-
const eventEmitter = new
|
|
29
|
+
function createCache(store, arguments_) {
|
|
30
|
+
const eventEmitter = new eventemitter3_1.default();
|
|
24
31
|
return {
|
|
25
32
|
/**
|
|
26
33
|
* Wraps a function in cache. I.e., the first time the function is run,
|
|
@@ -33,7 +40,7 @@ export function createCache(store, arguments_) {
|
|
|
33
40
|
*/
|
|
34
41
|
async wrap(key, function_, ttl, refreshThreshold) {
|
|
35
42
|
const refreshThresholdConfig = refreshThreshold ?? arguments_?.refreshThreshold ?? 0;
|
|
36
|
-
return coalesceAsync(key, async () => {
|
|
43
|
+
return (0, promise_coalesce_1.coalesceAsync)(key, async () => {
|
|
37
44
|
const value = await store.get(key).catch(error => {
|
|
38
45
|
const errorEvent = { error, key, operation: 'wrap' };
|
|
39
46
|
eventEmitter.emit('error', errorEvent);
|
|
@@ -53,7 +60,7 @@ export function createCache(store, arguments_) {
|
|
|
53
60
|
const cacheTtl = typeof ttl === 'function' ? ttl(value) : ttl;
|
|
54
61
|
const remainingTtl = await store.ttl(key);
|
|
55
62
|
if (remainingTtl !== -1 && remainingTtl < refreshThresholdConfig) {
|
|
56
|
-
coalesceAsync(`+++${key}`, function_)
|
|
63
|
+
(0, promise_coalesce_1.coalesceAsync)(`+++${key}`, function_)
|
|
57
64
|
.then(async (result) => store.set(key, result, cacheTtl))
|
|
58
65
|
.catch(async (error) => {
|
|
59
66
|
const errorEvent = {
|
|
@@ -83,4 +90,5 @@ export function createCache(store, arguments_) {
|
|
|
83
90
|
removeListener: (event, handler) => eventEmitter.removeListener(event, handler),
|
|
84
91
|
};
|
|
85
92
|
}
|
|
93
|
+
exports.createCache = createCache;
|
|
86
94
|
//# sourceMappingURL=caching.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./caching.js"), exports);
|
|
18
|
+
__exportStar(require("./multi-caching.js"), exports);
|
|
19
|
+
__exportStar(require("./stores/index.js"), exports);
|
|
4
20
|
//# sourceMappingURL=index.js.map
|
package/dist/multi-caching.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.multiCaching = void 0;
|
|
7
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
2
8
|
/**
|
|
3
9
|
* Module that lets you specify a hierarchy of caches.
|
|
4
10
|
*/
|
|
5
|
-
|
|
6
|
-
const eventEmitter = new
|
|
11
|
+
function multiCaching(caches) {
|
|
12
|
+
const eventEmitter = new eventemitter3_1.default();
|
|
7
13
|
for (const cache of caches) {
|
|
8
14
|
cache.on('error', event => eventEmitter.emit('error', event));
|
|
9
15
|
}
|
|
@@ -120,4 +126,5 @@ export function multiCaching(caches) {
|
|
|
120
126
|
removeListener: (event, handler) => eventEmitter.removeListener(event, handler),
|
|
121
127
|
};
|
|
122
128
|
}
|
|
129
|
+
exports.multiCaching = multiCaching;
|
|
123
130
|
//# sourceMappingURL=multi-caching.js.map
|
package/dist/stores/index.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./memory.js"), exports);
|
|
2
18
|
//# sourceMappingURL=index.js.map
|
package/dist/stores/memory.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.memoryStore = void 0;
|
|
7
|
+
const lru_cache_1 = require("lru-cache");
|
|
8
|
+
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
3
9
|
function clone(object) {
|
|
4
10
|
if (typeof object === 'object' && object !== null) {
|
|
5
|
-
return
|
|
11
|
+
return (0, lodash_clonedeep_1.default)(object);
|
|
6
12
|
}
|
|
7
13
|
return object;
|
|
8
14
|
}
|
|
9
15
|
/**
|
|
10
16
|
* Wrapper for lru-cache.
|
|
11
17
|
*/
|
|
12
|
-
|
|
18
|
+
function memoryStore(arguments_) {
|
|
13
19
|
const shouldCloneBeforeSet = arguments_?.shouldCloneBeforeSet !== false; // Clone by default
|
|
14
20
|
const isCacheable = arguments_?.isCacheable ?? (value => value !== undefined);
|
|
15
21
|
const lruOptions = {
|
|
@@ -18,7 +24,7 @@ export function memoryStore(arguments_) {
|
|
|
18
24
|
max: arguments_?.max ?? 500,
|
|
19
25
|
ttl: arguments_?.ttl === undefined ? 0 : arguments_.ttl,
|
|
20
26
|
};
|
|
21
|
-
const lruCache = new LRUCache(lruOptions);
|
|
27
|
+
const lruCache = new lru_cache_1.LRUCache(lruOptions);
|
|
22
28
|
return {
|
|
23
29
|
async del(key) {
|
|
24
30
|
lruCache.delete(key);
|
|
@@ -81,4 +87,5 @@ export function memoryStore(arguments_) {
|
|
|
81
87
|
},
|
|
82
88
|
};
|
|
83
89
|
}
|
|
90
|
+
exports.memoryStore = memoryStore;
|
|
84
91
|
//# sourceMappingURL=memory.js.map
|