| 621 | } |
| 622 | |
| 623 | override invalidate(key: RedisArgument | null) { |
| 624 | if (key === null) { |
| 625 | // Server requested to invalidate all keys |
| 626 | const oldSize = this.size(); |
| 627 | this.clear(false); |
| 628 | // Record invalidations as server-initiated evictions |
| 629 | if (oldSize > 0) { |
| 630 | publish(CHANNELS.CACHE_EVICTION, () => ({ reason: 'invalidation', count: oldSize })); |
| 631 | } |
| 632 | this.emit("invalidate", key); |
| 633 | |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | const keySet = this.#keyToCacheKeySetMap.get(key.toString()); |
| 638 | if (keySet) { |
| 639 | let deletedCount = 0; |
| 640 | for (const cacheKey of keySet) { |
| 641 | const entry = this.#cacheKeyToEntryMap.get(cacheKey); |
| 642 | if (entry) { |
| 643 | entry.invalidate(); |
| 644 | deletedCount++; |
| 645 | } |
| 646 | this.#cacheKeyToEntryMap.delete(cacheKey); |
| 647 | } |
| 648 | this.#keyToCacheKeySetMap.delete(key.toString()); |
| 649 | if (deletedCount > 0) { |
| 650 | // Record invalidations as server-initiated evictions |
| 651 | publish(CHANNELS.CACHE_EVICTION, () => ({ reason: 'invalidation', count: deletedCount })); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | this.emit('invalidate', key); |
| 656 | } |
| 657 | |
| 658 | override clear(resetStats = true) { |
| 659 | const oldSize = this.#cacheKeyToEntryMap.size; |