interface CacheEntry { data: T; expiresAt: number; } const cache = new Map>(); const DEFAULT_TTL_MS = 2 * 60 * 1000; export function cacheSet(key: string, data: T, ttlMs = DEFAULT_TTL_MS): void { const expiresAt = ttlMs > 0 ? Date.now() + ttlMs : 0; cache.set(key, { data, expiresAt }); } export function cacheGet(key: string): T | undefined { const entry = cache.get(key); if (!entry) return undefined; if (entry.expiresAt > 0 && Date.now() > entry.expiresAt) { cache.delete(key); return undefined; } return entry.data as T; } export function cacheHas(key: string): boolean { return cacheGet(key) !== undefined; } export function cacheDelete(key: string): void { cache.delete(key); } export function cacheClear(): void { cache.clear(); } export function threadCacheKey(uri: string): string { return `thread:${uri}`; } export function timelineCacheKey(cursor?: string): string { return cursor ? `timeline:${cursor}` : 'timeline:first'; } export function feedCacheKey(feedUri: string): string { return `feed:${feedUri}`; }