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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Clear cache' implies a destructive/mutative operation, the description doesn't mention important behavioral aspects like whether this requires admin permissions, whether it affects site performance during clearing, what happens to cached data, or potential side effects. It provides minimal context beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a simple tool and front-loads the essential information immediately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive cache-clearing operation with no annotations and no output schema, the description is insufficient. It doesn't explain what 'clearing cache' entails operationally, what gets cleared, potential performance impacts, or what the tool returns. Given the complexity of cache operations and lack of structured documentation, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters (site and pattern) with clear descriptions. The description doesn't add any meaningful parameter semantics beyond what's in the schema. The baseline of 3 is appropriate when the schema does the heavy lifting for parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Clear cache') and target ('for a WordPress site'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from sibling tools like wp_cache_info or wp_cache_stats, which also relate to cache operations but serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There are several sibling cache-related tools (wp_cache_info, wp_cache_stats, wp_cache_warm), but the description doesn't indicate when clearing cache is appropriate versus checking cache status or warming cache.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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