* Set a value in the cache
(key: string, value: T, ttl?: number)
| 77 | * Set a value in the cache |
| 78 | */ |
| 79 | set<T>(key: string, value: T, ttl?: number): void { |
| 80 | // LRU eviction if at capacity |
| 81 | if (this.cache.size >= this.maxSize) { |
| 82 | const firstKey = this.cache.keys().next().value |
| 83 | if (firstKey) { |
| 84 | this.cache.delete(firstKey) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | this.cache.set(key, { |
| 89 | value, |
| 90 | expires: Date.now() + (ttl ?? this.defaultTtl), |
| 91 | hitCount: 0, |
| 92 | }) |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Invalidate entries matching a pattern |
no test coverage detected