@zenweb/cache 4.3.1 → 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/package.json +1 -1
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
|
}
|