Skip to main content
Glama

ReactBits MCP Server

by ceorkm
CacheManager.ts1.6 kB
import { CacheEntry } from '../types/index.js'; export class CacheManager { private cache: Map<string, CacheEntry<any>>; private defaultTTL: number = 3600000; // 1 hour constructor() { this.cache = new Map(); } get<T>(key: string): T | null { 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 as T; } set<T>(key: string, data: T, ttl?: number): void { const entry: CacheEntry<T> = { data, timestamp: Date.now(), ttl: ttl || this.defaultTTL, }; this.cache.set(key, entry); } delete(key: string): boolean { return this.cache.delete(key); } clear(): void { this.cache.clear(); } has(key: string): boolean { 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(): void { 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(): { size: number; keys: string[] } { this.cleanup(); // Clean up expired entries first return { size: this.cache.size, keys: Array.from(this.cache.keys()), }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ceorkm/reactbits-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server