/** * Memory Cache Adapter * Simple in-memory implementation */ import type { CacheAdapter, CacheConfig } from './interfaces'; export class MemoryCacheAdapter implements CacheAdapter { private cache = new Map(); private defaultTTL: number; constructor(config: CacheConfig = {}) { this.defaultTTL = config.defaultTTL || 3600; } async get(key: string): Promise { const item = this.cache.get(key); if (!item) return null; if (Date.now() > item.expiry) { this.cache.delete(key); return null; } return item.value as T; } async set(key: string, value: T, ttl?: number): Promise { const finalTTL = ttl || this.defaultTTL; this.cache.set(key, { value, expiry: Date.now() + (finalTTL * 1000) }); } async del(key: string): Promise { this.cache.delete(key); } async clear(): Promise { this.cache.clear(); } }