(incomingSizeBytes: number)
| 144 | } |
| 145 | |
| 146 | private evictIfNeeded(incomingSizeBytes: number): void { |
| 147 | // Evict by entry count |
| 148 | while (this.cache.size >= this.config.maxEntries) { |
| 149 | this.evictLRU(); |
| 150 | } |
| 151 | |
| 152 | // Evict by size if configured |
| 153 | if (this.config.maxSizeBytes) { |
| 154 | while ( |
| 155 | this.currentSizeBytes + incomingSizeBytes > |
| 156 | this.config.maxSizeBytes && |
| 157 | this.cache.size > 0 |
| 158 | ) { |
| 159 | this.evictLRU(); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | private evictLRU(): void { |
| 165 | let lruKey: string | null = null; |