Skip to main content
Glama
weak-cache.ts906 B
import type { TaskType } from '../workers/compute-worker'; function hash(str: string): string { let h = 0; for (let i = 0; i < str.length; i++) { h = ((h << 5) - h + str.charCodeAt(i)) | 0; } return h.toString(36); } export function getDataHash(data: any): string { const str = typeof data === 'string' ? data : JSON.stringify(data); return str.length > 500 ? hash(str) : str; } class CacheManager { private cache = new Map<string, Map<TaskType, any>>(); get(data: any, taskType: TaskType): any | null { return this.cache.get(getDataHash(data))?.get(taskType) ?? null; } set(data: any, taskType: TaskType, result: any): void { const key = getDataHash(data); if (!this.cache.has(key)) this.cache.set(key, new Map()); this.cache.get(key)!.set(taskType, result); } clear(): void { this.cache.clear(); } } export const globalCache = new CacheManager();

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/superglue-ai/superglue'

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