/** * Module-scoped in-memory cache with TTLs. No storage writes. * Entries are keyed by string; each has a TTL after which it is stale. */ const store = new Map() export function memGet(key: string, ttlMs: number): T | undefined { const hit = store.get(key) if (!hit || Date.now() - hit.at > ttlMs) return undefined return hit.data as T } export function memSet(key: string, data: T): void { store.set(key, { data, at: Date.now() }) } export async function memCached(key: string, ttlMs: number, fn: () => Promise): Promise { const hit = memGet(key, ttlMs) if (hit !== undefined) return hit const data = await fn() memSet(key, data) return data }