get_cache_stats
Retrieve cache usage statistics to monitor performance and optimize resource allocation in the Documentation Search MCP Server.
Instructions
Get statistics about the current cache usage.
Returns:
Dictionary with cache statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main handler function for the 'get_cache_stats' MCP tool. It checks if caching is enabled and returns detailed statistics from the SimpleCache instance, including persistence info.@mcp.tool() async def get_cache_stats(): """ Get statistics about the current cache usage. Returns: Dictionary with cache statistics """ if not cache: return {"enabled": False, "message": "Caching is not enabled"} stats = await cache.stats() details = { "enabled": True, **stats, } details["persistence"] = { "enabled": cache.persistence_enabled, "path": cache.persist_path, } return details
- The 'stats' method of the SimpleCache class, which computes and returns the cache statistics used by the get_cache_stats tool.async def stats(self) -> Dict[str, Any]: async with self._lock: expired_count = sum( 1 for entry in self.cache.values() if self._is_expired(entry["timestamp"]) ) return { "total_entries": len(self.cache), "expired_entries": expired_count, "active_entries": len(self.cache) - expired_count, "max_entries": self.max_entries, "ttl_hours": self.ttl_hours, "memory_usage_estimate": f"{len(str(self.cache)) / 1024:.2f} KB", }
- src/documentation_search_enhanced/main.py:790-790 (registration)The @mcp.tool() decorator registers the get_cache_stats function as an MCP tool.@mcp.tool()