@jayfong/x-server 2.108.4 → 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.
@@ -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 _x.x.redis.del(...redisKeys);
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
- if (keys.length) {
236
- return _x.x.redis.del(...keys);
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 0;
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(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
247
+ if (prefixes.some(prefix => k.startsWith(this.toRedisKey(prefix)))) {
251
248
  this.memoryCache.delete(k);
252
249
  }
253
250
  });
254
251
  }
255
- const keys = (await Promise.all(prefixes.map(prefix => _x.x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
256
- if (keys.length) {
257
- return _x.x.redis.del(...keys);
258
- }
259
- return 0;
252
+ return count;
260
253
  }
261
254
 
262
255
  /**
@@ -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;
@@ -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 x.redis.del(...redisKeys);
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
- if (keys.length) {
231
- return x.redis.del(...keys);
224
+ const count = keys.length ? await x.redis.del(...keys) : 0;
225
+ if (this.options.memory) {
226
+ this.memoryCache.clear();
232
227
  }
233
- return 0;
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(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
242
+ if (prefixes.some(prefix => k.startsWith(this.toRedisKey(prefix)))) {
246
243
  this.memoryCache.delete(k);
247
244
  }
248
245
  });
249
246
  }
250
- const keys = (await Promise.all(prefixes.map(prefix => x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
251
- if (keys.length) {
252
- return x.redis.del(...keys);
253
- }
254
- return 0;
247
+ return count;
255
248
  }
256
249
 
257
250
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.108.4",
3
+ "version": "2.108.6",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -73,12 +73,12 @@
73
73
  "supports-color": "^8",
74
74
  "svg-captcha": "^1.4.0",
75
75
  "tencentcloud-sdk-nodejs-sms": "^4.0.681",
76
- "ts-morph": "^21.0.1",
77
- "tsx": "^4.19.2",
76
+ "ts-morph": "^27.0.2",
77
+ "tsx": "^4.21.0",
78
78
  "unplugin-macros": "^0.16.0",
79
79
  "utf-8-validate": "^5.0.9",
80
80
  "vscode-generate-index-standalone": "^1.7.1",
81
- "vtils": "^4.130.1",
81
+ "vtils": "^4.135.0",
82
82
  "yaml": "^2.3.1",
83
83
  "yargs": "^17.4.1"
84
84
  },