export const cache = (ttl: number) => { type Cache = { promise: Promise, timestamp: number }; const store = new Map(); const get = async (key: string, fetcher: () => Promise) => { if (store.has(key)) { const cached = store.get(key)!; if (Date.now() - cached.timestamp < ttl) { return cached.promise; } else { store.delete(key); } } try { const promise = fetcher(); store.set(key, { promise, timestamp: Date.now() }); return promise; } catch (error) { store.delete(key); throw error; } } return { get }; };