interface CacheEntry { value: T; expiry: number; } class TimedCache { private cache = new Map>(); private ttl: number; // Time to live in milliseconds constructor(ttl: number) { this.ttl = ttl; } get(key: string): T | undefined { const entry = this.cache.get(key); if (!entry) { return undefined; } if (Date.now() > entry.expiry) { this.cache.delete(key); // Entry expired return undefined; } return entry.value; } set(key: string, value: T): void { const expiry = Date.now() + this.ttl; this.cache.set(key, { value, expiry }); } delete(key: string): void { this.cache.delete(key); } clear(): void { this.cache.clear(); } } export const postCache = new TimedCache(2 * 60 * 1000); // 2 minutes cache