(key: K, value: V)
| 44 | } |
| 45 | |
| 46 | set(key: K, value: V): void { |
| 47 | if (this.store.has(key)) { |
| 48 | this.store.delete(key); |
| 49 | } else if (this.store.size >= this.max) { |
| 50 | // Evict the oldest entry — first key in iteration order. |
| 51 | const oldest = this.store.keys().next().value; |
| 52 | if (oldest !== undefined) { |
| 53 | this.store.delete(oldest); |
| 54 | } |
| 55 | } |
| 56 | this.store.set(key, value); |
| 57 | } |
| 58 | |
| 59 | clear(): void { |
| 60 | this.store.clear(); |