Files
EpicNext-Cms/src/lib/cache.ts
T
SimoandCursor 9b47668fe9 chore: CSP script nonces, deploy health check, dead-code cleanup
Add per-request CSP nonces (drop script unsafe-inline), post-deploy /api/health gate, bump next-auth to beta.32, and remove unused motion/cache/permission helpers.

Co-authored-by: Cursor <[email protected]>
2026-07-21 20:27:08 +02:00

18 lines
450 B
TypeScript

type CacheEntry<T> = { data: T; expiresAt: number };
const store = new Map<string, CacheEntry<unknown>>();
export function cached<T>(
key: string,
ttlMs: number,
fn: () => Promise<T>,
): Promise<T> {
const existing = store.get(key);
if (existing && existing.expiresAt > Date.now()) {
return Promise.resolve(existing.data as T);
}
return fn().then((data) => {
store.set(key, { data, expiresAt: Date.now() + ttlMs });
return data;
});
}