| import { CACHE_TTL_MS } from "../config.js"; | |
| const store = new Map(); | |
| const MAX = 200; | |
| export function getCache(key) { | |
| const hit = store.get(key); | |
| if (!hit) return null; | |
| if (Date.now() > hit.expires) { | |
| store.delete(key); | |
| return null; | |
| } | |
| return hit.value; | |
| } | |
| export function setCache(key, value, ttl = CACHE_TTL_MS) { | |
| if (store.size >= MAX) { | |
| const firstKey = store.keys().next().value; | |
| store.delete(firstKey); | |
| } | |
| store.set(key, { value, expires: Date.now() + ttl }); | |
| } | |