clear_cache
Remove specific or all cached entries to free memory and ensure fresh data retrieval in the Memory Cache MCP Server.
Instructions
Clear specific or all cache entries
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Specific key to clear (optional - clears all if not provided) |
Implementation Reference
- src/index.ts:203-228 (handler)Handler function for the 'clear_cache' tool. Parses arguments, calls CacheManager.delete(key) for specific key or CacheManager.clear() for all entries, and returns success/error text response.case 'clear_cache': { const { key } = request.params.arguments as { key?: string }; if (key) { const success = this.cacheManager.delete(key); return { content: [ { type: 'text', text: success ? `Successfully cleared cache entry: ${key}` : `No cache entry found for key: ${key}`, }, ], }; } else { this.cacheManager.clear(); return { content: [ { type: 'text', text: 'Successfully cleared all cache entries', }, ], }; } }
- src/index.ts:135-147 (registration)Tool registration in ListToolsRequestSchema handler, including name, description, and input schema.{ name: 'clear_cache', description: 'Clear specific or all cache entries', inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'Specific key to clear (optional - clears all if not provided)', }, }, }, },
- src/index.ts:138-146 (schema)Input schema definition for the clear_cache tool.inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'Specific key to clear (optional - clears all if not provided)', }, }, },
- src/CacheManager.ts:102-105 (helper)CacheManager.clear() method: clears all cache entries and resets statistics.clear(): void { this.cache.clear(); this.resetStats(); }
- src/CacheManager.ts:91-100 (helper)CacheManager.delete(key) method: removes specific cache entry and updates stats, returns success boolean.delete(key: string): boolean { const entry = this.cache.get(key); if (entry) { this.stats.memoryUsage -= entry.size; this.cache.delete(key); this.stats.totalEntries = this.cache.size; return true; } return false; }