baja-lite 1.8.3 → 1.8.4
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/package.json +1 -1
- package/sql.d.ts +1 -1
- package/sql.js +7 -6
package/package.json
CHANGED
package/sql.d.ts
CHANGED
|
@@ -2139,7 +2139,7 @@ export declare function clearMethodCache(key: string): Promise<void>;
|
|
|
2139
2139
|
*/
|
|
2140
2140
|
export declare function excuteWithCache<T>(config: {
|
|
2141
2141
|
/** 返回缓存key,参数=方法的参数+当前用户对象,可以用来清空缓存。 */
|
|
2142
|
-
key: string;
|
|
2142
|
+
key: ((...args: any[]) => string) | string;
|
|
2143
2143
|
/** 返回缓存清除key,参数=方法的参数+当前用户对象,可以用来批量清空缓存 */
|
|
2144
2144
|
clearKey?: string[];
|
|
2145
2145
|
/** 自动清空缓存的时间,单位分钟 */
|
package/sql.js
CHANGED
|
@@ -5166,7 +5166,7 @@ export async function GetRedisLock(key, lockMaxActive) {
|
|
|
5166
5166
|
;
|
|
5167
5167
|
/** 对FN加锁、缓存执行 */
|
|
5168
5168
|
export async function excuteWithLock(config, fn__) {
|
|
5169
|
-
const key = `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
|
|
5169
|
+
const key = config.key_real ? `[lock]${config.key_real}` : `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
|
|
5170
5170
|
const db = getRedisDB();
|
|
5171
5171
|
let wait_time = 0;
|
|
5172
5172
|
const fn = async () => {
|
|
@@ -5202,7 +5202,7 @@ export function MethodLock(config) {
|
|
|
5202
5202
|
return function (target, _propertyKey, descriptor) {
|
|
5203
5203
|
const fn__ = descriptor.value;
|
|
5204
5204
|
descriptor.value = async function (...args) {
|
|
5205
|
-
config.
|
|
5205
|
+
config.key_real = typeof config.key === 'function' ? config.key.call(target, ...args) : config.key;
|
|
5206
5206
|
return await excuteWithLock(config, async () => await fn__.call(this, ...args));
|
|
5207
5207
|
};
|
|
5208
5208
|
};
|
|
@@ -5283,16 +5283,17 @@ async function clearParent(clearKey) {
|
|
|
5283
5283
|
*/
|
|
5284
5284
|
export async function excuteWithCache(config, fn) {
|
|
5285
5285
|
const db = getRedisDB();
|
|
5286
|
-
const
|
|
5286
|
+
const key = typeof config.key === 'function' ? config.key() : config.key;
|
|
5287
|
+
const cache = await db.get(`[cache]${key}`);
|
|
5287
5288
|
if (cache) {
|
|
5288
|
-
globalThis[_LoggerService].debug?.(`cache ${
|
|
5289
|
+
globalThis[_LoggerService].debug?.(`cache ${key} hit!`);
|
|
5289
5290
|
return JSON.parse(cache);
|
|
5290
5291
|
}
|
|
5291
5292
|
else {
|
|
5292
|
-
globalThis[_LoggerService].debug?.(`cache ${config.key} miss!`);
|
|
5293
5293
|
const result = await fn();
|
|
5294
|
+
globalThis[_LoggerService].debug?.(`cache ${key} miss!`);
|
|
5294
5295
|
await setMethodCache({
|
|
5295
|
-
key
|
|
5296
|
+
key,
|
|
5296
5297
|
clearKey: config.clearKey,
|
|
5297
5298
|
autoClearTime: config.autoClearTime,
|
|
5298
5299
|
result
|