wp_cache_stats
Retrieve cache statistics for WordPress sites to monitor performance and optimize speed by analyzing cache hit rates and memory usage.
Instructions
Get cache statistics for a WordPress site.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | Site ID to get cache stats for. If not provided, uses default site or fails if multiple sites configured. |
Implementation Reference
- src/tools/cache.ts:81-110 (handler)The handler function that implements the core logic of the wp_cache_stats tool. It resolves the WordPress client for the given site, checks if caching is enabled, retrieves cache statistics from the CachedWordPressClient, and formats the response with hit/miss rates, total entries, evictions, and invalidation stats.async handleGetCacheStats(params: { site?: string }) { return toolWrapper(async () => { const client = this.resolveClient(params.site); if (!(client instanceof CachedWordPressClient)) { return { caching_enabled: false, message: "Caching is disabled for this site. Set DISABLE_CACHE=false to enable caching.", }; } const stats = client.getCacheStats(); return { caching_enabled: true, cache_stats: { hits: stats.cache.hits, misses: stats.cache.misses, hit_rate: Math.round(stats.cache.hitRate * 100) + "%", total_entries: stats.cache.totalSize, evictions: stats.cache.evictions, }, invalidation_stats: { queue_size: stats.invalidation.queueSize, rules_count: stats.invalidation.rulesCount, processing: stats.invalidation.processing, }, }; }); }
- src/tools/cache.ts:21-33 (registration)The tool definition object within CacheTools.getTools() that registers the wp_cache_stats tool, including name, description, input parameters (site), and binding to the handler method.{ name: "wp_cache_stats", description: "Get cache statistics for a WordPress site.", parameters: [ { name: "site", type: "string", description: "Site ID to get cache stats for. If not provided, uses default site or fails if multiple sites configured.", }, ], handler: this.handleGetCacheStats.bind(this), },
- src/server/ToolRegistry.ts:45-63 (registration)The registration logic in ToolRegistry that instantiates CacheTools with the WordPress clients map and registers all tools returned by getTools(), including wp_cache_stats.public registerAllTools(): void { // Register all tools from the tools directory Object.values(Tools).forEach((ToolClass) => { let toolInstance: { getTools(): unknown[] }; // Cache and Performance tools need the clients map if (ToolClass.name === "CacheTools" || ToolClass.name === "PerformanceTools") { toolInstance = new ToolClass(this.wordpressClients); } else { toolInstance = new (ToolClass as new () => { getTools(): unknown[] })(); } const tools = toolInstance.getTools(); tools.forEach((tool: unknown) => { this.registerTool(tool as ToolDefinition); }); }); }
- src/tools/cache.ts:24-31 (schema)The input schema definition for the wp_cache_stats tool, specifying the optional 'site' parameter.parameters: [ { name: "site", type: "string", description: "Site ID to get cache stats for. If not provided, uses default site or fails if multiple sites configured.", }, ],