clear_vision_cache
Clears the image understanding cache by forcing cached data from memory to disk and returns updated cache statistics.
Instructions
清除图片理解缓存(手动触发)
将内存中的缓存数据强制写入磁盘,并返回当前缓存统计。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/minimax_mcp/server.py:147-158 (registration)MCP tool registration for 'clear_vision_cache' - decorated with @mcp.tool(), imports and delegates to the real handler in image_understand.py
# ═══════════════════════════════════════════════════════════ # Tool 5: 清除视觉分析缓存 # ═══════════════════════════════════════════════════════════ @mcp.tool() def clear_vision_cache() -> dict: """清除图片理解缓存(手动触发) 将内存中的缓存数据强制写入磁盘,并返回当前缓存统计。 """ from minimax_mcp.tools.image_understand import clear_vision_cache as _run return _run() - Handler function for clear_vision_cache - calls flush_cache() to persist in-memory cache to disk and returns cache stats
def clear_vision_cache() -> dict: """清除视觉分析缓存(手动触发)""" flush_cache() return {"success": True, "message": "Vision cache flushed to disk", "stats": get_cache_stats()} - Helper functions get_cache_stats() and flush_cache() that delegate to the global VisionCache instance
def get_cache_stats() -> dict: """获取缓存统计""" return _get_cache().stats() def flush_cache(): """强制刷缓存到磁盘""" _get_cache().flush() - VisionCache.flush() method - public method that forces the in-memory cache to be written to disk
def flush(self): """强制刷盘""" self._flush() - VisionCache._flush() internal method - writes cached entries to a JSON file atomically (via .tmp file + replace)
def _flush(self): if not self._dirty: return try: data = { "updated": time.time(), "entries": list(self._memory.items()), } self._disk_path.parent.mkdir(parents=True, exist_ok=True) tmp = self._disk_path.with_suffix(".tmp") tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8") tmp.replace(self._disk_path) self._dirty = False except Exception: pass # 磁盘写入失败不影响主流程