Skip to main content
Glama
manager.ts1.19 kB
interface CacheEntry<T> { data: T; expiresAt: number; } export class CacheManager { private cache = new Map<string, CacheEntry<any>>(); private defaultTTL: number; private cleanupInterval: NodeJS.Timeout; constructor(ttlMs: number = 5 * 60 * 1000) { this.defaultTTL = ttlMs; this.cleanupInterval = setInterval(() => this.cleanup(), 60000); } get<T>(key: string): T | null { const entry = this.cache.get(key); if (!entry) { return null; } if (Date.now() > entry.expiresAt) { this.cache.delete(key); return null; } return entry.data as T; } set<T>(key: string, data: T, ttlMs?: number): void { const ttl = ttlMs ?? this.defaultTTL; this.cache.set(key, { data, expiresAt: Date.now() + ttl, }); } clear(): void { this.cache.clear(); } private cleanup(): void { const now = Date.now(); for (const [key, entry] of this.cache.entries()) { if (now > entry.expiresAt) { this.cache.delete(key); } } } destroy(): void { clearInterval(this.cleanupInterval); this.cache.clear(); } } export const cacheManager = new CacheManager(5 * 60 * 1000);

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/infil00p/DriveBC_MCP'

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