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
- Always flush after
wp search-replace— cached option values may contain the old string. - Flush after database imports — the cache may hold data from before the import.
- Add flush to deployment scripts — prevent stale cache from masking new changes.
- Combine with
wp rewrite flushafter permalink-related changes.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Site still shows stale data after flush | Page cache (Varnish, CDN) separate from object cache | Purge the page/CDN cache separately |
Error: Failed to flush the cache | Cache backend connection issue | Check 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
wp cache type— identify what cache backend is active.wp transient delete --expired— clean up expired transients alongside cache flush.wp rewrite flush— flush permalink rules after migration.