@jayfong/x-server 2.37.1 → 2.38.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.
@@ -224,6 +224,13 @@ class CacheService {
224
224
  * 清空全部缓存。
225
225
  */
226
226
  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
+ }
227
234
  const keys = await _x.x.redis.keys(`${this.prefix}*`);
228
235
  if (keys.length) {
229
236
  return _x.x.redis.del(...keys);
@@ -238,6 +245,13 @@ class CacheService {
238
245
  if (!prefixes.length) {
239
246
  return 0;
240
247
  }
248
+ if (this.options.memory) {
249
+ this.memoryCache.forEach((_v, k) => {
250
+ if (prefixes.some(prefix => k.startsWith(prefix))) {
251
+ this.memoryCache.delete(k);
252
+ }
253
+ });
254
+ }
241
255
  const keys = (await Promise.all(prefixes.map(prefix => _x.x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
242
256
  if (keys.length) {
243
257
  return _x.x.redis.del(...keys);
@@ -4,7 +4,7 @@ import { BaseService } from './base';
4
4
  export interface CacheServiceOptions {
5
5
  /** 默认过期时间 */
6
6
  ttl: MsValue;
7
- /** 启用内存缓存,仅 get, set, remove, remember 支持 */
7
+ /** 启用内存缓存,仅 get, set, remove, remember, clear, clearAll 支持 */
8
8
  memory?: boolean;
9
9
  }
10
10
  type Data = {
@@ -219,6 +219,13 @@ export class CacheService {
219
219
  * 清空全部缓存。
220
220
  */
221
221
  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
+ }
222
229
  const keys = await x.redis.keys(`${this.prefix}*`);
223
230
  if (keys.length) {
224
231
  return x.redis.del(...keys);
@@ -233,6 +240,13 @@ export class CacheService {
233
240
  if (!prefixes.length) {
234
241
  return 0;
235
242
  }
243
+ if (this.options.memory) {
244
+ this.memoryCache.forEach((_v, k) => {
245
+ if (prefixes.some(prefix => k.startsWith(prefix))) {
246
+ this.memoryCache.delete(k);
247
+ }
248
+ });
249
+ }
236
250
  const keys = (await Promise.all(prefixes.map(prefix => x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
237
251
  if (keys.length) {
238
252
  return x.redis.del(...keys);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.37.1",
3
+ "version": "2.38.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",