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
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | Site ID to clear cache for. | |
| pattern | No | Optional pattern to clear specific cache entries (e.g., "posts", "categories"). |
Implementation Reference
- src/tools/cache.ts:115-145 (handler)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, }; } }); }
- src/tools/cache.ts:34-50 (registration)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); }
- src/cache/CacheManager.ts:178-182 (helper)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; }