WP-CLI Cache Commands
Cache commands manage the WordPress object cache and transients from the terminal. Essential after deployments, migrations, and configuration changes — stale cache is one of the most common causes of unexpected behavior after updates.
Commands
wp cache flush
Clears the entire WordPress object cache.
wp cache flush
The most-used cache command. Clears whatever object cache backend is active — Redis, Memcached, or the default in-memory cache. Run after deployments, theme switches, plugin updates, and database imports. If something looks wrong after an update — this is the first command to run.
wp cache type
Shows the active cache backend.
wp cache type
Returns the cache driver in use: Redis, Memcached, or the WordPress default (non-persistent). Useful when diagnosing caching behavior or verifying that a persistent cache is actually connected.
wp cache get
Retrieves a value from the object cache.
wp cache get my_key my_group
wp cache get my_key my_group --format=json
Reads a cached value by key and group. Useful when debugging whether a value is being cached correctly and what it contains.
wp cache set
Stores a value in the object cache.
wp cache set my_key "my_value" my_group 3600
Arguments: key, value, group, expiration in seconds. Primarily useful for testing cache behavior or manually seeding cache values during debugging.
wp cache delete
Removes a specific value from the object cache.
wp cache delete my_key my_group
Removes one cached item by key and group. Use when you need to invalidate a specific cached value without flushing everything.
wp cache add
Adds a value to the cache only if the key does not already exist.
wp cache add my_key "my_value" my_group 3600
Will not overwrite an existing cached value. Useful for testing cache write behavior.
wp transient get / set / delete
Manages WordPress transients — time-limited values stored in the database or object cache.
wp transient get my_transient
wp transient set my_transient "value" 3600
wp transient delete my_transient
wp transient delete --all
wp transient list
Transients are used extensively by plugins to cache API responses and computed data. --all deletes every transient at once — useful when debugging stale plugin data or cleaning a bloated wp_options table.
Common Workflows
Post-deployment cache flush
wp core update
wp plugin update --all
wp cache flush
Standard end of every deployment sequence. Always flush after code or database changes.
Debug stale data after plugin update
wp cache flush
wp transient delete --all
If something looks wrong after a plugin update — flush object cache first, then clear transients. Covers both persistent cache and database-stored cache in one pass.
Check cache backend before debugging
wp cache type
Before spending time debugging caching issues — confirm what backend is actually running. A site that’s supposed to use Redis but falls back to default in-memory cache will behave very differently.
Clean bloated wp_options table
wp transient list --format=count
wp transient delete --all
wp db optimize
Check how many transients are stored, delete them all, then optimize the table. Common maintenance task on sites that use many third-party API integrations.
Notes on Cache Backends
WordPress supports three cache backends:
Default (in-memory) — built into WordPress, non-persistent. Cache exists only for the duration of a single request. wp cache flush has no real effect between requests.
Redis — persistent object cache. Survives requests and server restarts. Requires a Redis server and a drop-in plugin like redis-cache. wp cache flush clears the Redis store.
Memcached — persistent object cache. Similar to Redis. Requires Memcached PHP extension and a compatible drop-in.
If wp cache type returns Default on a site that should have Redis — the drop-in is missing or not connected. Check with wp plugin status redis-cache.
Related Command Groups
- Core — flush cache after core updates
- Plugins — flush after plugin updates
- Database — transients are stored in wp_options when no persistent cache is active
Practice Cases
- WordPress maintenance workflow (coming soon)
- CI/CD pipeline setup (coming soon)