* Set cached values for a field * @param fieldName The field name * @param values The values to cache * @param cacheKey Additional key for filtering (e.g., folder path)
(fieldName: string, values: Set<string>, cacheKey?: string)
| 65 | * @param cacheKey Additional key for filtering (e.g., folder path) |
| 66 | */ |
| 67 | set(fieldName: string, values: Set<string>, cacheKey?: string): void { |
| 68 | const key = this.makeKey(fieldName, cacheKey); |
| 69 | |
| 70 | // Limit the number of values per entry |
| 71 | const limitedValues = new Set<string>(); |
| 72 | let count = 0; |
| 73 | for (const value of values) { |
| 74 | if (count >= this.MAX_VALUES_PER_ENTRY) break; |
| 75 | limitedValues.add(value); |
| 76 | count++; |
| 77 | } |
| 78 | |
| 79 | // Check if we need to evict old entries |
| 80 | if (this.cache.size >= this.MAX_CACHE_ENTRIES && !this.cache.has(key)) { |
| 81 | this.evictOldestEntries(1); |
| 82 | } |
| 83 | |
| 84 | this.cache.set(key, { |
| 85 | values: limitedValues, |
| 86 | timestamp: Date.now(), |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Evict the oldest cache entries |