Skip to main content

wp cache flush

Overview

Purge all data from the WordPress object cache in a single command. The most commonly used cache command — run this after any migration, search-replace, import, or significant configuration change to eliminate stale cached data.

What It Does

wp cache flush calls wp_cache_flush(), which clears the entire object cache — both in-memory (current request) and persistent backends (Redis, Memcached) if one is configured.

Syntax

wp cache flush

No arguments or flags are needed.

Basic Usage

wp cache flush

Output:

Success: The cache was flushed.

When to Run

# After a domain/URL migration
wp search-replace 'https://old.com' 'https://new.com' --skip-columns=guid
wp cache flush

# After importing content
wp import content.xml --authors=create
wp cache flush

# After activating or deactivating plugins
wp plugin activate woocommerce
wp cache flush

# After updating site options
wp option update siteurl 'https://new.com'
wp cache flush

# After a database import
wp db import backup.sql
wp cache flush

Real-World Scenarios

Scenario 1: Post-migration flush routine

#!/bin/bash
# post-migration.sh

echo "Step 1: Run search-replace..."
wp search-replace 'https://old-site.com' 'https://new-site.com' --skip-columns=guid

echo "Step 2: Flush rewrite rules..."
wp rewrite flush

echo "Step 3: Flush object cache..."
wp cache flush

echo "Step 4: Verify site URL..."
wp option get siteurl

echo "Migration complete."

Scenario 2: Maintenance script

#!/bin/bash
# weekly-maintenance.sh

wp db optimize
wp transient delete --expired
wp cache flush
echo "Maintenance done: $(date)"

Scenario 3: Multi-site network flush

# Flush cache on every site in the network
for url in $(wp site list --field=url); do
wp cache flush --url="$url"
echo "Flushed: $url"
done

Persistent Cache Notes

Redis / Memcached

If a persistent cache plugin (e.g., Redis Object Cache, W3 Total Cache) is installed, wp cache flush clears that backend too. Without a persistent cache, the in-memory cache only exists for the duration of the current WP-CLI process.

Best Practices

  1. Always flush after wp search-replace — cached option values may contain the old string.
  2. Flush after database imports — the cache may hold data from before the import.
  3. Add flush to deployment scripts — prevent stale cache from masking new changes.
  4. Combine with wp rewrite flush after permalink-related changes.

Troubleshooting

ProblemCauseFix
Site still shows stale data after flushPage cache (Varnish, CDN) separate from object cachePurge the page/CDN cache separately
Error: Failed to flush the cacheCache backend connection issueCheck Redis/Memcached service status

Quick Reference

wp cache flush                              # Flush all cache
wp cache flush --url=https://sub.example.com # Specific multisite
wp cache type # Check cache backend

Next Steps