Skip to main content
Glama
default-cache.ts1.28 kB
import type { Cache } from '@/typings/index.js'; import { get } from '@/utils/index.js'; export class DefaultCache implements Cache { values: Map< string | symbol, { value: any; expiredTime?: number; } >; constructor() { this.values = new Map(); } // When there is a namespace, splice the namespace and key to form a new key private getCacheKey(key: string | symbol, namespace?: string) { if (namespace) { return `${namespace}/${key.toString()}`; } return key; } async get( key: string | symbol, options?: { namespace?: string; }, ) { const cacheKey = this.getCacheKey(key, get(options, 'namespace')); const data = this.values.get(cacheKey); if (data) { const { value, expiredTime } = data; if (!expiredTime || expiredTime - new Date().getTime() > 0) { return value; } } return undefined; } async set( key: string | symbol, value: string, expiredTime?: number, options?: { namespace?: string; }, ) { const cacheKey = this.getCacheKey(key, get(options, 'namespace')); this.values.set(cacheKey, { value, expiredTime, }); return true; } } export const internalCache = new DefaultCache();

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/sdd330/feishu-mcp-server'

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