Skip to main content
Glama
haasonsaas
by haasonsaas

cache_put

Store JSON-serializable data in the cache with a specified TTL (Time to Live) to efficiently manage API responses, computed values, or other frequently accessed data.

Instructions

Store a value in the cache with TTL. Useful for caching API responses, computed values, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesCache key
namespaceNoOptional namespace to prevent key collisionsdefault
ttl_secondsNoTime to live in seconds
valueYesValue to cache (any JSON-serializable data)

Implementation Reference

  • Handler function for the 'cache_put' tool. Parses arguments, computes expiration time, stores the entry in the cache Map, and returns success response with metadata.
    case "cache_put": { const { key, value, ttl_seconds = 300 } = args as any; const expiresAt = Date.now() + (ttl_seconds * 1000); cache.set(key, { value, expiresAt }); return { content: [{ type: "text", text: JSON.stringify({ success: true, key, ttl_seconds, expires_at: new Date(expiresAt).toISOString() }) }] }; }
  • Input schema definition for the 'cache_put' tool, specifying parameters key (required string), value (required any), and ttl_seconds (optional number with defaults and bounds).
    { name: "cache_put", description: "Store a value in the cache with TTL", inputSchema: { type: "object", properties: { key: { type: "string", description: "Cache key" }, value: { description: "Value to cache (any JSON-serializable data)" }, ttl_seconds: { type: "number", description: "Time to live in seconds", default: 300, minimum: 1, maximum: 86400 // 24 hours } }, required: ["key", "value"] } },
  • src/index.ts:189-191 (registration)
    Registration of the list tools handler, which exposes the 'cache_put' tool (included in the tools array) to MCP clients.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
  • Cache storage using Map<string, CacheEntry> to hold cache entries with value and expiration timestamp, used by cache_put handler.
    // Cache storage with TTL support interface CacheEntry { value: any; expiresAt: number; } const cache = new Map<string, CacheEntry>();
  • Periodic cleanup interval that removes expired entries from the cache, supporting the TTL functionality of cache_put.
    // 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

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