import { LRUCache } from 'lru-cache'; /** * In-memory TTL cache backed by an LRU cache to prevent memory leaks. */ export class MemoryCache { private lru: LRUCache; constructor(ttlMs: number, max = 1000) { this.lru = new LRUCache({ max, ttl: ttlMs, ttlAutopurge: true }); } get(key: string): T | undefined { return this.lru.get(key); } set(key: string, value: T): void { this.lru.set(key, value); } has(key: string): boolean { return this.lru.has(key); } delete(key: string): void { this.lru.delete(key); } clear(): void { this.lru.clear(); } }