@midwayjs/cache-manager 3.19.2 → 4.0.0-alpha.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.
|
@@ -46,7 +46,7 @@ function createCache(store, args) {
|
|
|
46
46
|
await store.set(key, result, cacheTTL);
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
49
|
-
else if (args
|
|
49
|
+
else if (args?.refreshThreshold) {
|
|
50
50
|
const cacheTTL = typeof ttl === 'function' ? ttl(value) : ttl;
|
|
51
51
|
const remainingTtl = await store.ttl(key);
|
|
52
52
|
if (remainingTtl !== -1 && remainingTtl < args.refreshThreshold) {
|
|
@@ -73,7 +73,7 @@ function createCache(store, args) {
|
|
|
73
73
|
await store.set(key, result, cacheTTL);
|
|
74
74
|
return result;
|
|
75
75
|
}
|
|
76
|
-
else if (args
|
|
76
|
+
else if (args?.refreshThreshold) {
|
|
77
77
|
const cacheTTL = typeof ttl === 'function' ? ttl(value) : ttl;
|
|
78
78
|
const remainingTtl = await store.ttl(key);
|
|
79
79
|
if (remainingTtl !== -1 && remainingTtl < args.refreshThreshold) {
|
|
@@ -50,8 +50,7 @@ function addCallbackToKey(key, callback) {
|
|
|
50
50
|
callbacks.set(key, stash);
|
|
51
51
|
}
|
|
52
52
|
function getCallbacksByKey(key) {
|
|
53
|
-
|
|
54
|
-
return (_a = callbacks.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
53
|
+
return callbacks.get(key) ?? [];
|
|
55
54
|
}
|
|
56
55
|
function enqueue(key) {
|
|
57
56
|
return new Promise((resolve, reject) => {
|
package/dist/base/store.js
CHANGED
|
@@ -13,14 +13,13 @@ function clone(object) {
|
|
|
13
13
|
* Wrapper for lru-cache.
|
|
14
14
|
*/
|
|
15
15
|
function memoryStore(args) {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const isCacheable = (_a = args === null || args === void 0 ? void 0 : args.isCacheable) !== null && _a !== void 0 ? _a : (val => val !== undefined);
|
|
16
|
+
const shouldCloneBeforeSet = args?.shouldCloneBeforeSet !== false; // clone by default
|
|
17
|
+
const isCacheable = args?.isCacheable ?? (val => val !== undefined);
|
|
19
18
|
const lruOpts = {
|
|
20
19
|
ttlAutopurge: true,
|
|
21
20
|
...args,
|
|
22
|
-
max:
|
|
23
|
-
ttl:
|
|
21
|
+
max: args?.max || 500,
|
|
22
|
+
ttl: args?.ttl !== undefined ? args.ttl : 0,
|
|
24
23
|
};
|
|
25
24
|
const lruCache = new LRUCache(lruOpts);
|
|
26
25
|
return {
|
package/dist/configuration.js
CHANGED
|
@@ -14,7 +14,11 @@ const core_1 = require("@midwayjs/core");
|
|
|
14
14
|
const cacheKey_1 = require("./decorator/cacheKey");
|
|
15
15
|
const factory_1 = require("./factory");
|
|
16
16
|
function getClassMethodDefaultCacheKey(target, methodName) {
|
|
17
|
-
return target.name +
|
|
17
|
+
return (target.name +
|
|
18
|
+
'-' +
|
|
19
|
+
core_1.DecoratorManager.getProviderUUId(target) +
|
|
20
|
+
'-' +
|
|
21
|
+
methodName);
|
|
18
22
|
}
|
|
19
23
|
exports.getClassMethodDefaultCacheKey = getClassMethodDefaultCacheKey;
|
|
20
24
|
let CacheConfiguration = class CacheConfiguration {
|
|
@@ -48,11 +52,12 @@ let CacheConfiguration = class CacheConfiguration {
|
|
|
48
52
|
});
|
|
49
53
|
}
|
|
50
54
|
};
|
|
55
|
+
exports.CacheConfiguration = CacheConfiguration;
|
|
51
56
|
__decorate([
|
|
52
57
|
(0, core_1.Inject)(),
|
|
53
58
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
54
59
|
], CacheConfiguration.prototype, "decoratorService", void 0);
|
|
55
|
-
CacheConfiguration = __decorate([
|
|
60
|
+
exports.CacheConfiguration = CacheConfiguration = __decorate([
|
|
56
61
|
(0, core_1.Configuration)({
|
|
57
62
|
namespace: 'cacheManager',
|
|
58
63
|
importConfigs: [
|
|
@@ -64,5 +69,4 @@ CacheConfiguration = __decorate([
|
|
|
64
69
|
],
|
|
65
70
|
})
|
|
66
71
|
], CacheConfiguration);
|
|
67
|
-
exports.CacheConfiguration = CacheConfiguration;
|
|
68
72
|
//# sourceMappingURL=configuration.js.map
|
|
@@ -8,7 +8,7 @@ function Caching(cacheInstanceName, cacheKeyOrTTL, ttl) {
|
|
|
8
8
|
ttl = cacheKeyOrTTL;
|
|
9
9
|
cacheKeyOrTTL = undefined;
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return core_1.DecoratorManager.createCustomMethodDecorator(exports.CACHE_DECORATOR_KEY, {
|
|
12
12
|
cacheInstanceName,
|
|
13
13
|
cacheKey: cacheKeyOrTTL,
|
|
14
14
|
ttl,
|
package/dist/factory.js
CHANGED
|
@@ -70,6 +70,7 @@ let CachingFactory = class CachingFactory extends core_1.ServiceFactory {
|
|
|
70
70
|
return this.get(cacheKey);
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
+
exports.CachingFactory = CachingFactory;
|
|
73
74
|
__decorate([
|
|
74
75
|
(0, core_1.Config)('cacheManager'),
|
|
75
76
|
__metadata("design:type", Object)
|
|
@@ -84,9 +85,8 @@ __decorate([
|
|
|
84
85
|
__metadata("design:paramtypes", []),
|
|
85
86
|
__metadata("design:returntype", Promise)
|
|
86
87
|
], CachingFactory.prototype, "init", null);
|
|
87
|
-
CachingFactory = __decorate([
|
|
88
|
+
exports.CachingFactory = CachingFactory = __decorate([
|
|
88
89
|
(0, core_1.Provide)(),
|
|
89
90
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
90
91
|
], CachingFactory);
|
|
91
|
-
exports.CachingFactory = CachingFactory;
|
|
92
92
|
//# sourceMappingURL=factory.js.map
|
package/dist/store.js
CHANGED
|
@@ -13,7 +13,7 @@ function createRedisStore(instanceName) {
|
|
|
13
13
|
}
|
|
14
14
|
exports.createRedisStore = createRedisStore;
|
|
15
15
|
function createStore(redisCache, options) {
|
|
16
|
-
const isCacheable =
|
|
16
|
+
const isCacheable = options?.isCacheable || (value => value !== undefined && value !== null);
|
|
17
17
|
const keys = (pattern) => redisCache.keys(pattern);
|
|
18
18
|
return {
|
|
19
19
|
async get(key) {
|
|
@@ -32,14 +32,14 @@ function createStore(redisCache, options) {
|
|
|
32
32
|
async set(key, value, ttl) {
|
|
33
33
|
if (!isCacheable(value))
|
|
34
34
|
throw new core_1.MidwayCommonError(`"${value}" is not a cacheable value`);
|
|
35
|
-
const t = ttl === undefined ? options
|
|
35
|
+
const t = ttl === undefined ? options?.ttl : ttl;
|
|
36
36
|
if (t !== undefined && t !== 0)
|
|
37
37
|
await redisCache.set(key, getVal(value), 'PX', t);
|
|
38
38
|
else
|
|
39
39
|
await redisCache.set(key, getVal(value));
|
|
40
40
|
},
|
|
41
41
|
async mset(args, ttl) {
|
|
42
|
-
const t = ttl === undefined ? options
|
|
42
|
+
const t = ttl === undefined ? options?.ttl : ttl;
|
|
43
43
|
if (t !== undefined && t !== 0) {
|
|
44
44
|
const multi = redisCache.multi();
|
|
45
45
|
for (const [key, value] of args) {
|
|
@@ -64,7 +64,7 @@ function createStore(redisCache, options) {
|
|
|
64
64
|
try {
|
|
65
65
|
return JSON.parse(x);
|
|
66
66
|
}
|
|
67
|
-
catch
|
|
67
|
+
catch {
|
|
68
68
|
return x;
|
|
69
69
|
}
|
|
70
70
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/cache-manager",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "midway cache manager",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit"
|
|
11
11
|
},
|
|
12
12
|
"author": "",
|
|
13
13
|
"files": [
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"node": ">=12"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@midwayjs/core": "^
|
|
32
|
-
"@midwayjs/mock": "^
|
|
33
|
-
"@midwayjs/redis": "^
|
|
31
|
+
"@midwayjs/core": "^4.0.0-alpha.1",
|
|
32
|
+
"@midwayjs/mock": "^4.0.0-alpha.1",
|
|
33
|
+
"@midwayjs/redis": "^4.0.0-alpha.1",
|
|
34
34
|
"cache-manager": "6.0.0",
|
|
35
35
|
"cache-manager-ioredis-yet": "2.1.2"
|
|
36
36
|
},
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"lodash.clonedeep": "4.5.0",
|
|
39
39
|
"lru-cache": "7.18.3"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
42
42
|
}
|