* Get a value from the cache
(key: string)
| 50 | * Get a value from the cache |
| 51 | */ |
| 52 | get<T>(key: string): T | null { |
| 53 | const entry = this.cache.get(key) |
| 54 | |
| 55 | if (!entry) { |
| 56 | this.misses++ |
| 57 | return null |
| 58 | } |
| 59 | |
| 60 | // Check expiration |
| 61 | if (Date.now() > entry.expires) { |
| 62 | this.cache.delete(key) |
| 63 | this.misses++ |
| 64 | return null |
| 65 | } |
| 66 | |
| 67 | // Update hit count and move to end (LRU) |
| 68 | entry.hitCount++ |
| 69 | this.cache.delete(key) |
| 70 | this.cache.set(key, entry) |
| 71 | |
| 72 | this.hits++ |
| 73 | return entry.value as T |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Set a value in the cache |
no test coverage detected