cache_clear
Remove all entries from the cache or target a specific namespace to optimize storage and performance. Ideal for managing cached data effectively.
Instructions
Clear all entries from the cache or a specific namespace
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | Clear only this namespace, or all if not specified |
Implementation Reference
- src/index.ts:341-354 (handler)Handler for the cache_clear tool: clears all entries in the shared cache Map and returns the count of cleared entries in a text content response.case "cache_clear": { const size = cache.size; cache.clear(); return { content: [{ type: "text", text: JSON.stringify({ success: true, cleared_entries: size }) }] }; }
- src/index.ts:136-143 (registration)Tool registration entry for cache_clear in the tools array returned by listTools, defining name, description, and input schema (no parameters).{ name: "cache_clear", description: "Clear all entries from the cache", inputSchema: { type: "object", properties: {} } },
- src/index-v2.ts:482-519 (handler)Handler for cache_clear in v2 implementation: supports clearing a specific namespace (prefix-based) or the entire cache, returns cleared count.case "cache_clear": { const { namespace } = args as any; if (namespace) { let cleared = 0; const prefix = `${namespace}:`; for (const key of cache.keys()) { if (key.startsWith(prefix)) { cache.delete(key); cleared++; } } return { content: [{ type: "text", text: JSON.stringify({ success: true, namespace, cleared_entries: cleared }) }] }; } else { const size = cache.size; cache.clear(); return { content: [{ type: "text", text: JSON.stringify({ success: true, cleared_entries: size }) }] }; } }
- src/index-v2.ts:163-175 (registration)Tool registration for cache_clear in v2 tools array, with schema supporting optional namespace parameter.{ name: "cache_clear", description: "Clear all entries from the cache or a specific namespace", inputSchema: { type: "object", properties: { namespace: { type: "string", description: "Clear only this namespace, or all if not specified" } } } },
- src/index.ts:18-19 (helper)Shared cache storage Map used by cache_clear and other cache tools.const cache = new Map<string, CacheEntry>();