wp_cache_warm
Pre-warm WordPress cache by loading essential site data to improve page load times and reduce server load for visitors.
Instructions
Pre-warm cache with essential WordPress data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | Site ID to warm cache for. |
Implementation Reference
- src/tools/cache.ts:150-172 (handler)The main handler function for the 'wp_cache_warm' tool. It resolves the appropriate CachedWordPressClient instance and calls its warmCache() method to pre-populate the cache with essential data like user info, categories, tags, and site settings.async handleWarmCache(params: { site?: string }) { return toolWrapper(async () => { const client = this.resolveClient(params.site); if (!(client instanceof CachedWordPressClient)) { return { success: false, message: "Caching is not enabled for this site.", }; } await client.warmCache(); const stats = client.getCacheStats(); return { success: true, message: "Cache warmed with essential WordPress data.", cache_entries_after_warming: stats.cache.totalSize, warmed_data: ["Current user information", "Categories", "Tags", "Site settings"], }; }); }
- The core cache warming implementation in CachedWordPressClient. Pre-loads essential WordPress data (current user, categories, tags, site settings) into the cache in parallel, ignoring individual failures.async warmCache(): Promise<void> { try { // Pre-load frequently accessed data const warmupOperations = [ () => this.getCurrentUser().catch(() => null), () => this.getCategories().catch(() => null), () => this.getTags().catch(() => null), () => this.getSiteSettings().catch(() => null), ]; // Execute warmup operations in parallel await Promise.allSettled(warmupOperations.map((op) => op())); } catch (_error) { // Ignore warmup errors - they shouldn't fail the cache warming } }
- src/tools/cache.ts:51-62 (registration)Tool definition and registration object for 'wp_cache_warm' returned by CacheTools.getTools(), including name, description, parameters schema, and handler binding.{ name: "wp_cache_warm", description: "Pre-warm cache with essential WordPress data.", parameters: [ { name: "site", type: "string", description: "Site ID to warm cache for.", }, ], handler: this.handleWarmCache.bind(this), },
- src/server/ToolRegistry.ts:46-62 (registration)Registration of CacheTools instance in ToolRegistry.registerAllTools(), which instantiates CacheTools with wordpressClients map and registers all its tools (including wp_cache_warm) with the MCP server.// 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); }); });