Skip to main content
Glama

wp_cache_clear

Clear WordPress site cache to resolve display issues and ensure content updates appear immediately. Optionally target specific cache entries like posts or categories.

Instructions

Clear cache for a WordPress site.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
siteNoSite ID to clear cache for.
patternNoOptional pattern to clear specific cache entries (e.g., "posts", "categories").

Implementation Reference

  • The main handler function for the wp_cache_clear tool. Resolves the site client, checks if caching is enabled, and calls client.clearCache() or client.clearCachePattern(params.pattern) based on whether a pattern is provided. Returns success status and cleared count.
    async handleClearCache(params: { site?: string; pattern?: 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.",
          };
        }
    
        let cleared: number;
    
        if (params.pattern) {
          cleared = client.clearCachePattern(params.pattern);
          return {
            success: true,
            message: `Cleared ${cleared} cache entries matching pattern "${params.pattern}".`,
            cleared_entries: cleared,
            pattern: params.pattern,
          };
        } else {
          cleared = client.clearCache();
          return {
            success: true,
            message: `Cleared all cache entries (${cleared} total).`,
            cleared_entries: cleared,
          };
        }
      });
    }
  • Tool registration within CacheTools.getTools(). Defines name, description, input parameters (site and optional pattern), and binds the handler.
    {
      name: "wp_cache_clear",
      description: "Clear cache for a WordPress site.",
      parameters: [
        {
          name: "site",
          type: "string",
          description: "Site ID to clear cache for.",
        },
        {
          name: "pattern",
          type: "string",
          description: 'Optional pattern to clear specific cache entries (e.g., "posts", "categories").',
        },
      ],
      handler: this.handleClearCache.bind(this),
    },
  • clearCache method in CachedWordPressClient, called by the tool handler when no pattern is specified. Clears the cache via cacheManager.clear() and returns the previous total size.
    clearCache(): number {
      const stats = this.cacheManager.getStats();
      this.cacheManager.clear();
      return stats.totalSize;
    }
  • clearCachePattern method in CachedWordPressClient, called by the tool handler when pattern is provided. Creates case-insensitive regex and calls cacheManager.clearPattern().
    clearCachePattern(pattern: string): number {
      const regex = new RegExp(pattern, "i");
      return this.cacheManager.clearPattern(regex);
    }
  • Core clear() method in CacheManager that performs the actual cache clearing by clearing the internal Map, resetting access order array, and updating stats.
    clear(): void {
      this.cache.clear();
      this.accessOrder = [];
      this.stats.totalSize = 0;
    }

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