UNPKG

reactbits-dev-mcp-server

Version:

MCP server providing access to 135+ animated React components from ReactBits.dev

63 lines 1.59 kB
export class CacheManager { cache; defaultTTL = 3600000; // 1 hour constructor() { this.cache = new Map(); } get(key) { const entry = this.cache.get(key); if (!entry) { return null; } // Check if entry has expired if (Date.now() > entry.timestamp + entry.ttl) { this.cache.delete(key); return null; } return entry.data; } set(key, data, ttl) { const entry = { data, timestamp: Date.now(), ttl: ttl || this.defaultTTL, }; this.cache.set(key, entry); } delete(key) { return this.cache.delete(key); } clear() { this.cache.clear(); } has(key) { const entry = this.cache.get(key); if (!entry) { return false; } // Check if entry has expired if (Date.now() > entry.timestamp + entry.ttl) { this.cache.delete(key); return false; } return true; } // Clean up expired entries cleanup() { const now = Date.now(); for (const [key, entry] of this.cache.entries()) { if (now > entry.timestamp + entry.ttl) { this.cache.delete(key); } } } // Get cache statistics getStats() { this.cleanup(); // Clean up expired entries first return { size: this.cache.size, keys: Array.from(this.cache.keys()), }; } } //# sourceMappingURL=CacheManager.js.map