| 706 | } |
| 707 | |
| 708 | set(cacheKey: string, cacheEntry: ClientSideCacheEntry, keys: Array<RedisArgument>) { |
| 709 | let count = this.#cacheKeyToEntryMap.size; |
| 710 | const oldEntry = this.#cacheKeyToEntryMap.get(cacheKey); |
| 711 | |
| 712 | if (oldEntry) { |
| 713 | count--; // overwriting, so not incrementing |
| 714 | oldEntry.invalidate(); |
| 715 | } |
| 716 | |
| 717 | if (this.maxEntries > 0 && count >= this.maxEntries) { |
| 718 | this.deleteOldest(); |
| 719 | this.#statsCounter.recordEvictions(1); |
| 720 | // Eviction due to cache capacity limit |
| 721 | publish(CHANNELS.CACHE_EVICTION, () => ({ reason: 'full', count: 1 })); |
| 722 | } |
| 723 | |
| 724 | this.#cacheKeyToEntryMap.set(cacheKey, cacheEntry); |
| 725 | |
| 726 | for (const key of keys) { |
| 727 | if (!this.#keyToCacheKeySetMap.has(key.toString())) { |
| 728 | this.#keyToCacheKeySetMap.set(key.toString(), new Set<string>()); |
| 729 | } |
| 730 | |
| 731 | const cacheKeySet = this.#keyToCacheKeySetMap.get(key.toString()); |
| 732 | cacheKeySet!.add(cacheKey); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | size() { |
| 737 | return this.#cacheKeyToEntryMap.size; |