(path: string)
| 46 | } |
| 47 | |
| 48 | function readCache<T>(path: string): T | undefined { |
| 49 | try { |
| 50 | const entry = JSON.parse(readFileSync(path, "utf-8")) as CacheEntry<T>; |
| 51 | if (typeof entry.fetchedAt !== "number") return undefined; |
| 52 | if (Date.now() - entry.fetchedAt > CACHE_TTL_MS) return undefined; |
| 53 | return entry.data; |
| 54 | } catch { |
| 55 | // Missing file or corrupt JSON → cache miss. |
| 56 | return undefined; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | function writeCache<T>(path: string, data: T): void { |
| 61 | try { |
no test coverage detected