@jayfong/x-server 2.51.1 → 2.52.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.
|
@@ -247,7 +247,7 @@ class CacheService {
|
|
|
247
247
|
}
|
|
248
248
|
if (this.options.memory) {
|
|
249
249
|
this.memoryCache.forEach((_v, k) => {
|
|
250
|
-
if (prefixes.some(prefix => k.startsWith(prefix))) {
|
|
250
|
+
if (prefixes.some(prefix => k.startsWith(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
|
|
251
251
|
this.memoryCache.delete(k);
|
|
252
252
|
}
|
|
253
253
|
});
|
package/lib/services/cache.d.ts
CHANGED
|
@@ -18,11 +18,14 @@ type KeyPathForNumberValue<T extends Data> = {
|
|
|
18
18
|
[K in keyof T]: T[K] extends (...args: infer X) => number ? IsEmptyArray<X> extends true ? K : [K, ...X] : never;
|
|
19
19
|
}[keyof T];
|
|
20
20
|
type Value<T extends Data, P extends KeyPath<T>> = ReturnType<T[P extends any[] ? P[0] : P]>;
|
|
21
|
+
type KeyPartialPath<T extends Data> = {
|
|
22
|
+
[K in keyof T]: T[K] extends (...args: infer X) => any ? IsEmptyArray<X> extends true ? K : [K, ...Partial<X>] : never;
|
|
23
|
+
}[keyof T];
|
|
21
24
|
type CacheSetTTL<V> = MsValue | ((data: V, defaultTTL: MsValue) => MsValue);
|
|
22
25
|
type CacheSetOptions<V> = CacheSetTTL<V> | {
|
|
23
26
|
ttl?: CacheSetTTL<V>;
|
|
24
27
|
};
|
|
25
|
-
export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any> implements BaseService {
|
|
28
|
+
export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any, TKeyPartialPath extends KeyPartialPath<TData> = any> implements BaseService {
|
|
26
29
|
options: CacheServiceOptions;
|
|
27
30
|
serviceName: string;
|
|
28
31
|
private prefix;
|
|
@@ -118,11 +121,11 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
|
|
|
118
121
|
/**
|
|
119
122
|
* 清空指定前缀的缓存。
|
|
120
123
|
*/
|
|
121
|
-
clear
|
|
124
|
+
clear(...prefixes: Array<TKey | TKeyPartialPath>): Promise<number>;
|
|
122
125
|
/**
|
|
123
126
|
* 派生出一个指定类型的缓存服务。
|
|
124
127
|
*/
|
|
125
|
-
fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>>;
|
|
128
|
+
fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>, KeyPartialPath<TNextData>>;
|
|
126
129
|
}
|
|
127
130
|
declare module '../x' {
|
|
128
131
|
interface X {
|
package/lib/services/cache.js
CHANGED
|
@@ -242,7 +242,7 @@ export class CacheService {
|
|
|
242
242
|
}
|
|
243
243
|
if (this.options.memory) {
|
|
244
244
|
this.memoryCache.forEach((_v, k) => {
|
|
245
|
-
if (prefixes.some(prefix => k.startsWith(prefix))) {
|
|
245
|
+
if (prefixes.some(prefix => k.startsWith(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
|
|
246
246
|
this.memoryCache.delete(k);
|
|
247
247
|
}
|
|
248
248
|
});
|