MCPcopy
hub / github.com/redis/node-redis / invalidate

Method invalidate

packages/client/lib/client/cache.ts:623–656  ·  view source on GitHub ↗
(key: RedisArgument | null)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 7

sizeMethod · 0.95
clearMethod · 0.95
publishFunction · 0.90
deleteMethod · 0.80
toStringMethod · 0.65
invalidateMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected