clear_cache
Clear cached data from the Word Document Reader MCP Server to free up resources and ensure accurate document processing. Specify what to clear: all data, documents only, or search indexes.
Instructions
清空所有缓存
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | 清除类型:all, document, index | all |
Implementation Reference
- server.js:820-849 (handler)Main execution logic for the clear_cache tool. Handles input 'type' parameter to selectively clear document cache, index, or all caches (including memory cache via documentCache.flushAll()), and returns a success message.case "clear_cache": { const { type = "all" } = args; switch (type) { case "document": await cacheManager.clear(); var clearedMessage = "已清空文档缓存"; break; case "index": documentIndexer.clear(); var clearedMessage = "已清空全文索引"; break; case "all": default: await cacheManager.clear(); documentIndexer.clear(); documentCache.flushAll(); var clearedMessage = "已清空所有缓存(文档缓存、全文索引、内存缓存)"; break; } return { content: [ { type: "text", text: clearedMessage } ] }; }
- server.js:550-564 (registration)Tool registration in ListToolsRequestSchema handler, defining name, description, and input schema for clear_cache.{ name: "clear_cache", description: "清空所有缓存", inputSchema: { type: "object", properties: { type: { type: "string", description: "清除类型:all, document, index", enum: ["all", "document", "index"], default: "all" } } } },
- server.js:419-428 (helper)CacheManager.clear() method: Clears file-based document cache by removing all cache files (except metadata.json) and resetting metadata.async clear() { await this.initialize(); const files = await fs.readdir(this.cacheDir); for (const file of files) { if (file !== 'metadata.json') { await fs.remove(path.join(this.cacheDir, file)); } } await fs.writeJson(this.metadataFile, {}); }
- server.js:133-137 (helper)DocumentIndexer.clear() method: Clears the full-text index Map and documents Map, updates lastUpdated timestamp.clear() { this.index.clear(); this.documents.clear(); this.lastUpdated = Date.now(); }
- server.js:38-42 (helper)documentCache NodeCache instance used for in-memory document storage, cleared via flushAll() in the handler.const documentCache = new NodeCache({ stdTTL: 3600, // 1小时缓存 checkperiod: 600, // 每10分钟检查过期缓存 useClones: false });