Skip to main content
Glama
haasonsaas
by haasonsaas

cache_get

Retrieve cached data by specifying a key using this tool. Optionally, use a namespace to avoid key conflicts. Returns null if the key is not found or expired.

Instructions

Get a value from the cache by key. Returns null if not found or expired.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesCache key to retrieve
namespaceNoOptional namespace to prevent key collisionsdefault

Implementation Reference

  • src/index.ts:84-97 (registration)
    Registration of the 'cache_get' tool in the tools list, including name, description, and input schema.
    { name: "cache_get", description: "Get a value from the cache by key", inputSchema: { type: "object", properties: { key: { type: "string", description: "Cache key to retrieve" } }, required: ["key"] } },
  • The handler logic for the 'cache_get' tool. It retrieves the cache entry by key, checks if it exists and is not expired, and returns a JSON response with the value or appropriate error information.
    case "cache_get": { const { key } = args as { key: string }; const entry = cache.get(key); if (!entry) { return { content: [{ type: "text", text: JSON.stringify({ found: false, key }) }] }; } // Check if expired if (entry.expiresAt <= Date.now()) { cache.delete(key); return { content: [{ type: "text", text: JSON.stringify({ found: false, key, reason: "expired" }) }] }; } return { content: [{ type: "text", text: JSON.stringify({ found: true, key, value: entry.value, expires_in_seconds: Math.floor((entry.expiresAt - Date.now()) / 1000) }) }] }; }
  • Cache storage implementation using a Map with TTL support, including CacheEntry interface, the cache Map, and periodic cleanup interval used by cache_get.
    interface CacheEntry { value: any; expiresAt: number; } const cache = new Map<string, CacheEntry>(); // Clean up expired cache entries periodically setInterval(() => { const now = Date.now(); for (const [key, entry] of cache.entries()) { if (entry.expiresAt <= now) { cache.delete(key); } } }, 60000); // Clean every minute
  • src/index-v2.ts:96-113 (registration)
    Registration of the enhanced 'cache_get' tool in index-v2.ts with namespace support.
    { name: "cache_get", description: "Get a value from the cache by key. Returns null if not found or expired.", inputSchema: { type: "object", properties: { key: { type: "string", description: "Cache key to retrieve" }, namespace: { type: "string", description: "Optional namespace to prevent key collisions", default: "default" } }, required: ["key"] }
  • The handler logic for 'cache_get' in v2 version, supporting namespaces via getCacheKey helper.
    case "cache_get": { const { key, namespace = "default" } = args as any; const cacheKey = getCacheKey(key, namespace); const entry = cache.get(cacheKey); if (!entry) { return { content: [{ type: "text", text: JSON.stringify({ found: false, key, namespace }) }] }; } // Check if expired if (entry.expiresAt <= Date.now()) { cache.delete(cacheKey); return { content: [{ type: "text", text: JSON.stringify({ found: false, key, namespace, reason: "expired" }) }] }; } return { content: [{ type: "text", text: JSON.stringify({ found: true, key, namespace, value: entry.value, expires_in_seconds: Math.floor((entry.expiresAt - Date.now()) / 1000) }) }] }; }

Other Tools

Related Tools

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/haasonsaas/mcp-utility-tools'

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