Skip to main content
Glama

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 entries

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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")
  • 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,
            }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apiarya/wemo-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server