* Set an entry in the cache.
(key: string, data: T, hash: string, sizeBytes = 0)
| 71 | * Set an entry in the cache. |
| 72 | */ |
| 73 | set(key: string, data: T, hash: string, sizeBytes = 0): void { |
| 74 | // Evict if necessary |
| 75 | this.evictIfNeeded(sizeBytes); |
| 76 | |
| 77 | // Delete existing entry first to update size tracking |
| 78 | if (this.cache.has(key)) { |
| 79 | this.delete(key); |
| 80 | } |
| 81 | |
| 82 | const entry: CacheEntry<T> = { |
| 83 | data, |
| 84 | hash, |
| 85 | timestamp: Date.now(), |
| 86 | accessCount: 1, |
| 87 | sizeBytes, |
| 88 | }; |
| 89 | |
| 90 | this.cache.set(key, entry); |
| 91 | this.currentSizeBytes += sizeBytes; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Delete an entry from the cache. |
no test coverage detected