Skip to main content
Glama

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
NameRequiredDescriptionDefault
siteNoSite ID to warm cache for.

Implementation Reference

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

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/docdyhr/mcp-wordpress'

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