* Get entry only if hash matches (for conditional updates).
(key: string, hash: string)
| 49 | * Get entry only if hash matches (for conditional updates). |
| 50 | */ |
| 51 | getIfHashMatches(key: string, hash: string): T | null { |
| 52 | const entry = this.cache.get(key); |
| 53 | if (!entry) return null; |
| 54 | |
| 55 | // Check TTL |
| 56 | if (Date.now() - entry.timestamp > this.config.maxAge) { |
| 57 | this.delete(key); |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | // Check hash |
| 62 | if (entry.hash !== hash) { |
| 63 | return null; |
| 64 | } |
| 65 | |
| 66 | entry.accessCount++; |
| 67 | return entry.data; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Set an entry in the cache. |
no test coverage detected