* Gets a value from cache
(key: string)
| 57 | * Gets a value from cache |
| 58 | */ |
| 59 | get(key: string): T | null { |
| 60 | const entry = this.cache.get(key); |
| 61 | |
| 62 | if (!entry) { |
| 63 | if (this.options.enableStats) { |
| 64 | this.stats.misses++; |
| 65 | } |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | // Check if expired |
| 70 | if (this.isExpired(entry)) { |
| 71 | this.cache.delete(key); |
| 72 | if (this.options.enableStats) { |
| 73 | this.stats.misses++; |
| 74 | } |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | // Update access info |
| 79 | entry.lastAccessed = Date.now(); |
| 80 | entry.accessCount++; |
| 81 | |
| 82 | if (this.options.enableStats) { |
| 83 | this.stats.hits++; |
| 84 | } |
| 85 | |
| 86 | return entry.data; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Sets a value in cache |
no test coverage detected