@jayfong/x-server 2.108.5 → 2.108.6
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/lib/_cjs/services/cache.js +10 -17
- package/lib/services/cache.d.ts +3 -3
- package/lib/services/cache.js +10 -17
- package/package.json +1 -1
|
@@ -212,30 +212,25 @@ class CacheService {
|
|
|
212
212
|
return 0;
|
|
213
213
|
}
|
|
214
214
|
const redisKeys = keys.map(key => this.toRedisKey(key));
|
|
215
|
+
const count = await _x.x.redis.del(...redisKeys);
|
|
215
216
|
if (this.options.memory) {
|
|
216
217
|
redisKeys.forEach(redisKey => {
|
|
217
218
|
this.memoryCache.delete(redisKey);
|
|
218
219
|
});
|
|
219
220
|
}
|
|
220
|
-
return
|
|
221
|
+
return count;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
/**
|
|
224
225
|
* 清空全部缓存。
|
|
225
226
|
*/
|
|
226
227
|
async clearAll() {
|
|
227
|
-
if (this.options.memory) {
|
|
228
|
-
this.memoryCache.forEach((_v, k) => {
|
|
229
|
-
if (k.startsWith(this.prefix)) {
|
|
230
|
-
this.memoryCache.delete(k);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
228
|
const keys = await _x.x.redis.keys(`${this.prefix}*`);
|
|
235
|
-
|
|
236
|
-
|
|
229
|
+
const count = keys.length ? await _x.x.redis.del(...keys) : 0;
|
|
230
|
+
if (this.options.memory) {
|
|
231
|
+
this.memoryCache.clear();
|
|
237
232
|
}
|
|
238
|
-
return
|
|
233
|
+
return count;
|
|
239
234
|
}
|
|
240
235
|
|
|
241
236
|
/**
|
|
@@ -245,18 +240,16 @@ class CacheService {
|
|
|
245
240
|
if (!prefixes.length) {
|
|
246
241
|
return 0;
|
|
247
242
|
}
|
|
243
|
+
const keys = (await Promise.all(prefixes.map(prefix => _x.x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
|
|
244
|
+
const count = keys.length ? await _x.x.redis.del(...keys) : 0;
|
|
248
245
|
if (this.options.memory) {
|
|
249
246
|
this.memoryCache.forEach((_v, k) => {
|
|
250
|
-
if (prefixes.some(prefix => k.startsWith(
|
|
247
|
+
if (prefixes.some(prefix => k.startsWith(this.toRedisKey(prefix)))) {
|
|
251
248
|
this.memoryCache.delete(k);
|
|
252
249
|
}
|
|
253
250
|
});
|
|
254
251
|
}
|
|
255
|
-
|
|
256
|
-
if (keys.length) {
|
|
257
|
-
return _x.x.redis.del(...keys);
|
|
258
|
-
}
|
|
259
|
-
return 0;
|
|
252
|
+
return count;
|
|
260
253
|
}
|
|
261
254
|
|
|
262
255
|
/**
|
package/lib/services/cache.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MsValue } from 'vtils';
|
|
2
|
-
import { AsyncOrSync, IsEmptyArray } from 'vtils/types';
|
|
3
|
-
import { BaseService } from './base';
|
|
1
|
+
import { type MsValue } from 'vtils';
|
|
2
|
+
import type { AsyncOrSync, IsEmptyArray } from 'vtils/types';
|
|
3
|
+
import type { BaseService } from './base';
|
|
4
4
|
export interface CacheServiceOptions {
|
|
5
5
|
/** 默认过期时间 */
|
|
6
6
|
ttl: MsValue;
|
package/lib/services/cache.js
CHANGED
|
@@ -207,30 +207,25 @@ export class CacheService {
|
|
|
207
207
|
return 0;
|
|
208
208
|
}
|
|
209
209
|
const redisKeys = keys.map(key => this.toRedisKey(key));
|
|
210
|
+
const count = await x.redis.del(...redisKeys);
|
|
210
211
|
if (this.options.memory) {
|
|
211
212
|
redisKeys.forEach(redisKey => {
|
|
212
213
|
this.memoryCache.delete(redisKey);
|
|
213
214
|
});
|
|
214
215
|
}
|
|
215
|
-
return
|
|
216
|
+
return count;
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
/**
|
|
219
220
|
* 清空全部缓存。
|
|
220
221
|
*/
|
|
221
222
|
async clearAll() {
|
|
222
|
-
if (this.options.memory) {
|
|
223
|
-
this.memoryCache.forEach((_v, k) => {
|
|
224
|
-
if (k.startsWith(this.prefix)) {
|
|
225
|
-
this.memoryCache.delete(k);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
223
|
const keys = await x.redis.keys(`${this.prefix}*`);
|
|
230
|
-
|
|
231
|
-
|
|
224
|
+
const count = keys.length ? await x.redis.del(...keys) : 0;
|
|
225
|
+
if (this.options.memory) {
|
|
226
|
+
this.memoryCache.clear();
|
|
232
227
|
}
|
|
233
|
-
return
|
|
228
|
+
return count;
|
|
234
229
|
}
|
|
235
230
|
|
|
236
231
|
/**
|
|
@@ -240,18 +235,16 @@ export class CacheService {
|
|
|
240
235
|
if (!prefixes.length) {
|
|
241
236
|
return 0;
|
|
242
237
|
}
|
|
238
|
+
const keys = (await Promise.all(prefixes.map(prefix => x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
|
|
239
|
+
const count = keys.length ? await x.redis.del(...keys) : 0;
|
|
243
240
|
if (this.options.memory) {
|
|
244
241
|
this.memoryCache.forEach((_v, k) => {
|
|
245
|
-
if (prefixes.some(prefix => k.startsWith(
|
|
242
|
+
if (prefixes.some(prefix => k.startsWith(this.toRedisKey(prefix)))) {
|
|
246
243
|
this.memoryCache.delete(k);
|
|
247
244
|
}
|
|
248
245
|
});
|
|
249
246
|
}
|
|
250
|
-
|
|
251
|
-
if (keys.length) {
|
|
252
|
-
return x.redis.del(...keys);
|
|
253
|
-
}
|
|
254
|
-
return 0;
|
|
247
|
+
return count;
|
|
255
248
|
}
|
|
256
249
|
|
|
257
250
|
/**
|