Something went wrong. Try again.
My website. cameron.stream
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// Simple in-memory cache. Swap for Redis later if needed.
const LIFE_TTL: Record<string, number> = { seconds: 30, minutes: 5 * 60, hours: 3600, max: 86400,};
type CacheEntry = { value: unknown; expires: number;};
const store = new Map<string, CacheEntry>();
type CacheTag = { $type: string; uri?: string; subject?: string; from?: string;};
type CachePolicy = { life?: string; tags?: CacheTag[];};
export async function cacheGet(key: string): Promise<unknown | undefined> { 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<void> { const life = policy?.life ?? "hours"; const ttl = LIFE_TTL[life] ?? 3600; store.set(key, { value, expires: Date.now() + ttl * 1000, });}