* Retrieves a value from the cache if it exists and hasn't expired * @param {string} key - The cache key to retrieve * @returns {any|null} The cached value or null if not found or expired
(key: string)
| 28 | * @returns {any|null} The cached value or null if not found or expired |
| 29 | */ |
| 30 | get(key: string) { |
| 31 | const itemStr = localStorage.getItem(key); |
| 32 | if (!itemStr) { |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | const item = JSON.parse(itemStr); |
| 37 | if (Date.now() > item.expiration) { |
| 38 | localStorage.removeItem(key); |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | return item.value; |
| 43 | }, |
| 44 | |
| 45 | /** |
| 46 | * Removes a specific item from the cache |
no test coverage detected