@zenweb/cache 4.3.0 → 4.4.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/dist/cache.js +12 -0
- package/dist/types.d.ts +9 -0
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +2 -2
- package/package.json +9 -6
- package/CHANGELOG.md +0 -32
package/dist/cache.js
CHANGED
|
@@ -115,9 +115,17 @@ class Cache {
|
|
|
115
115
|
async lockGet(key, fetch, _opt) {
|
|
116
116
|
var _a, _b;
|
|
117
117
|
const opt = Object.assign({}, (_a = this.option) === null || _a === void 0 ? void 0 : _a.set, (_b = this.option) === null || _b === void 0 ? void 0 : _b.lockGet, _opt);
|
|
118
|
+
// 本地存储
|
|
119
|
+
if (opt.localStore && key in opt.localStore) {
|
|
120
|
+
return opt.localStore[key];
|
|
121
|
+
}
|
|
118
122
|
// 获取数据并设置到缓存中
|
|
119
123
|
const fetchAndSet = async () => {
|
|
120
124
|
const obj = await fetch();
|
|
125
|
+
// 本地存储
|
|
126
|
+
if (opt.localStore) {
|
|
127
|
+
opt.localStore[key] = obj;
|
|
128
|
+
}
|
|
121
129
|
const result = await this.set(key, obj, opt);
|
|
122
130
|
if ((_opt === null || _opt === void 0 ? void 0 : _opt.parse) !== false) {
|
|
123
131
|
return obj;
|
|
@@ -147,6 +155,10 @@ class Cache {
|
|
|
147
155
|
if (!locker) {
|
|
148
156
|
preRefresh();
|
|
149
157
|
}
|
|
158
|
+
// 本地存储
|
|
159
|
+
if (opt.localStore) {
|
|
160
|
+
opt.localStore[key] = data;
|
|
161
|
+
}
|
|
150
162
|
return data;
|
|
151
163
|
}
|
|
152
164
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -117,4 +117,13 @@ export interface LockGetOption extends GetOption, SetOption, LockOption {
|
|
|
117
117
|
* @default false
|
|
118
118
|
*/
|
|
119
119
|
refresh?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* 本地存储
|
|
122
|
+
* - 如果指定一个对象,则尝试先从对象中存取
|
|
123
|
+
* - 防止在同一次请求中重复从 Redis 获取
|
|
124
|
+
* - 一般情况下在 Context 中设置一个空对象并指定
|
|
125
|
+
*/
|
|
126
|
+
localStore?: {
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
};
|
|
120
129
|
}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cacheKey = exports.runRedisScript = exports.sleep = exports.debug = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@zenweb/core");
|
|
5
5
|
const crypto = require("crypto");
|
|
6
|
-
exports.debug = (0,
|
|
6
|
+
exports.debug = (0, core_1.zenwebDebug)('cache');
|
|
7
7
|
/**
|
|
8
8
|
* Promise 等待
|
|
9
9
|
* @param ms 毫秒
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenweb/cache",
|
|
3
|
-
"
|
|
3
|
+
"packageManager": "yarn@4.0.2",
|
|
4
|
+
"version": "4.4.0",
|
|
4
5
|
"description": "Zenweb Cache module",
|
|
5
6
|
"exports": "./dist/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
@@ -8,10 +9,11 @@
|
|
|
8
9
|
"dist"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
12
|
+
"vscode": "yarn dlx @yarnpkg/sdks vscode",
|
|
11
13
|
"build": "rimraf dist && tsc",
|
|
12
|
-
"prepublishOnly": "
|
|
14
|
+
"prepublishOnly": "yarn run build",
|
|
13
15
|
"test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
|
|
14
|
-
"dev": "cd example && cross-env DEBUG
|
|
16
|
+
"dev": "cd example && cross-env DEBUG=\\* NODE_ENV=development ts-node app"
|
|
15
17
|
},
|
|
16
18
|
"author": {
|
|
17
19
|
"name": "YeFei",
|
|
@@ -31,16 +33,17 @@
|
|
|
31
33
|
"homepage": "https://zenweb.node.ltd/docs/modules/cache",
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@types/mocha": "^10.0.1",
|
|
36
|
+
"@types/node": "^20.10.6",
|
|
34
37
|
"cross-env": "^7.0.3",
|
|
35
38
|
"mocha": "^10.2.0",
|
|
36
39
|
"rimraf": "^4.3.1",
|
|
37
40
|
"ts-mocha": "^10.0.0",
|
|
38
41
|
"ts-node": "^10.9.1",
|
|
39
|
-
"typescript": "^5.
|
|
40
|
-
"zenweb": "^4.
|
|
42
|
+
"typescript": "^5.3.3",
|
|
43
|
+
"zenweb": "^4.2.7"
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
|
-
"
|
|
46
|
+
"@zenweb/core": "^4.2.3",
|
|
44
47
|
"ioredis": "^5.3.2"
|
|
45
48
|
}
|
|
46
49
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [4.3.0] - 2023-12-14
|
|
4
|
-
normalKey 改名为 cacheKey
|
|
5
|
-
retryCount 参数说明,并修改默认值为 10
|
|
6
|
-
|
|
7
|
-
## [4.2.2] - 2023-8-23
|
|
8
|
-
修改: 除了 Buffer 类型意外全部都使用 JSON 序列化
|
|
9
|
-
|
|
10
|
-
## [4.2.1] - 2023-8-23
|
|
11
|
-
fix: 内容未压缩,客户端支持压缩内容时却标识为压缩内容
|
|
12
|
-
|
|
13
|
-
## [4.2.0] - 2023-8-22
|
|
14
|
-
更新: cached 中间件支持 null key,不使用缓存
|
|
15
|
-
|
|
16
|
-
## [4.1.3] - 2023-8-21
|
|
17
|
-
fix: 二次获取缓存数据时会返回压缩数据的问题
|
|
18
|
-
|
|
19
|
-
## [4.1.2] - 2023-8-21
|
|
20
|
-
fix: 首次缓存新数据时会返回压缩数据的问题
|
|
21
|
-
|
|
22
|
-
## [4.1.1] - 2023-8-18
|
|
23
|
-
增加 normalKey number 参数
|
|
24
|
-
|
|
25
|
-
## [4.1.0] - 2023-8-18
|
|
26
|
-
增加 normalKey 方法
|
|
27
|
-
|
|
28
|
-
## [4.0.1] - 2023-8-17
|
|
29
|
-
cached 中间件增加 type 参数
|
|
30
|
-
|
|
31
|
-
## [4.0.0] - 2023-8-8
|
|
32
|
-
发布
|