clear_cache
Clears persistent device cache to resolve issues when devices have changed or cache is corrupted. Removes cache file and in-memory cache. Run scan_network after to rebuild.
Instructions
Clear the persistent device cache.
Removes the cache file and clears in-memory cache. Useful when devices have changed or cache is corrupted. Run scan_network after clearing to rebuild the cache.
Returns
Dictionary containing:
- success: Whether cache was cleared successfully
- message: Descriptive messageInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/wemo_mcp_server/server.py:606-642 (handler)The clear_cache tool handler function. Decorated with @mcp.tool(), it clears both the persistent disk cache (via _cache_manager.clear()) and the in-memory device cache (_device_cache.clear()). Returns success/error response dict.
@mcp.tool() async def clear_cache() -> dict[str, Any]: """Clear the persistent device cache. Removes the cache file and clears in-memory cache. Useful when devices have changed or cache is corrupted. Run scan_network after clearing to rebuild the cache. Returns ------- Dictionary containing: - success: Whether cache was cleared successfully - message: Descriptive message """ try: # Clear persistent cache cache_cleared = _cache_manager.clear() # Clear in-memory cache _device_cache.clear() if cache_cleared: return { "success": True, "message": "Cache cleared successfully. Run scan_network to rebuild cache.", "timestamp": time.time(), } return { "success": False, "error": "Failed to clear cache file", "timestamp": time.time(), } except Exception as e: logger.error(f"Error clearing cache: {e}", exc_info=True) return build_error_response(e, "Clear cache") - src/wemo_mcp_server/server.py:606-607 (registration)Tool registration via @mcp.tool() decorator on the clear_cache async function. This registers the function as an MCP tool named 'clear_cache'.
@mcp.tool() async def clear_cache() -> dict[str, Any]: - src/wemo_mcp_server/cache.py:123-141 (helper)The DeviceCache.clear() method called by the clear_cache handler. Deletes the cache JSON file from disk and resets the in-memory _cache dict.
def clear(self) -> bool: """Clear the device cache (delete cache file). Returns ------- True if cleared successfully, False otherwise """ try: if self.cache_file.exists(): self.cache_file.unlink() logger.info(f"Cleared cache file at {self.cache_file}") self._cache = {} return True except OSError as e: logger.error(f"Failed to clear cache at {self.cache_file}: {e}") return False - The clear_cache tool's input/output contract: no input parameters (empty), returns a dict with success (bool), message (str), and timestamp. On error returns error response via build_error_response.
@mcp.tool() async def clear_cache() -> dict[str, Any]: """Clear the persistent device cache. Removes the cache file and clears in-memory cache. Useful when devices have changed or cache is corrupted. Run scan_network after clearing to rebuild the cache. Returns ------- Dictionary containing: - success: Whether cache was cleared successfully - message: Descriptive message """ try: # Clear persistent cache cache_cleared = _cache_manager.clear() # Clear in-memory cache _device_cache.clear() if cache_cleared: return { "success": True, "message": "Cache cleared successfully. Run scan_network to rebuild cache.", "timestamp": time.time(), } return { "success": False, "error": "Failed to clear cache file", "timestamp": time.time(), } except Exception as e: logger.error(f"Error clearing cache: {e}", exc_info=True) return build_error_response(e, "Clear cache")