// Simple in-memory cache. Swap for Redis later if needed. const LIFE_TTL: Record = { seconds: 30, minutes: 5 * 60, hours: 3600, max: 86400, }; type CacheEntry = { value: unknown; expires: number; }; const store = new Map(); type CacheTag = { $type: string; uri?: string; subject?: string; from?: string; }; type CachePolicy = { life?: string; tags?: CacheTag[]; }; export async function cacheGet(key: string): Promise { const entry = store.get(key); if (!entry) return undefined; if (Date.now() > entry.expires) { store.delete(key); return undefined; } return entry.value; } export async function cacheSet( key: string, value: unknown, policy?: CachePolicy ): Promise { const life = policy?.life ?? "hours"; const ttl = LIFE_TTL[life] ?? 3600; store.set(key, { value, expires: Date.now() + ttl * 1000, }); }