get_cache_info
Check cache status to determine if a device rescan is needed by retrieving file age, expiration status, and stored device count.
Instructions
Get information about the persistent device cache.
Returns information about the cache file including age, expiration status, and device count. Useful for determining if a rescan is needed.
Returns
Dictionary containing:
- exists: Whether cache file exists
- path: Path to cache file
- age_seconds: Age of cache in seconds
- expired: Whether cache has expired
- device_count: Number of devices in cache
- ttl_seconds: Time-to-live for cache entriesInput Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/wemo_mcp_server/server.py:580-604 (handler)The get_cache_info MCP tool handler, which calls the cache manager's get_cache_info method.
async def get_cache_info() -> dict[str, Any]: """Get information about the persistent device cache. Returns information about the cache file including age, expiration status, and device count. Useful for determining if a rescan is needed. Returns ------- Dictionary containing: - exists: Whether cache file exists - path: Path to cache file - age_seconds: Age of cache in seconds - expired: Whether cache has expired - device_count: Number of devices in cache - ttl_seconds: Time-to-live for cache entries """ try: cache_info = _cache_manager.get_cache_info() cache_info["memory_cache_size"] = len(_device_cache) return cache_info except Exception as e: logger.error(f"Error getting cache info: {e}", exc_info=True) return build_error_response(e, "Get cache info") - src/wemo_mcp_server/cache.py:164-202 (handler)The DeviceCache method that performs the actual logic for getting cache information from the file system.
def get_cache_info(self) -> dict[str, Any]: """Get information about the current cache. Returns ------- Dictionary with cache metadata """ if not self.cache_file.exists(): return { "exists": False, "path": str(self.cache_file), "ttl_seconds": self.ttl_seconds, } try: with self.cache_file.open() as f: data = json.load(f) cache_age = time.time() - data.get("timestamp", 0) return { "exists": True, "path": str(self.cache_file), "version": data.get("version"), "device_count": data.get("device_count", 0), "age_seconds": round(cache_age, 2), "ttl_seconds": self.ttl_seconds, "expired": cache_age > self.ttl_seconds, "created": data.get("timestamp"), } except (json.JSONDecodeError, OSError, KeyError) as e: return { "exists": True, "path": str(self.cache_file), "error": str(e), "ttl_seconds": self.ttl_seconds, }