wp cache delete
Overview
Surgically remove a single cache entry by key and group without flushing the entire cache. Use this when you need to invalidate one specific cached value while leaving all other cache data intact.
What It Does
wp cache delete calls wp_cache_delete() to remove the entry. On a persistent backend (Redis, Memcached), this immediately removes the key. On the in-memory default cache, it removes it for the lifetime of the current process.
Syntax
wp cache delete <key> [<group>]
Arguments
| Argument | Default | Description |
|---|---|---|
KEY | — | Cache key to delete |
GROUP | default | Cache group the key belongs to |
Basic Usage
Delete from the default group
wp cache delete my_cache_key
Delete from a specific group
wp cache delete product_count counts
Delete a post object from cache
wp cache delete 42 posts
Real-World Scenarios
Scenario 1: Force-refresh a single option without full flush
# Invalidate the alloptions cache after a manual DB update
wp cache delete alloptions options
# Next call to get_option() will reload fresh from the database
Scenario 2: Remove a stale WooCommerce product cache
PRODUCT_ID=123
# Delete cached product object
wp cache delete $PRODUCT_ID posts
# Delete related term/category caches
wp cache delete "woocommerce_product_cat_${PRODUCT_ID}" "product_cat"
Scenario 3: Release a cache lock
wp cache delete "cron_lock" locks
echo "Cache lock released."
Scenario 4: Targeted invalidation for a plugin
# Get the cache key pattern from plugin source code, then delete specifically
wp cache delete "my_plugin_home_feed" "my_plugin"
echo "Home feed cache invalidated — next request will regenerate it."
delete vs flush
| Command | Scope | Use When |
|---|---|---|
wp cache delete KEY | One specific entry | You know exactly which key is stale |
wp cache flush | All cached data | You want a full clean slate |
Best Practices
- Prefer targeted
deleteover fullflushon production —flushcauses a cache stampede where every request must re-fetch from the database simultaneously. - Know the group — deleting from the wrong group is a no-op. Check plugin source or
wp cache getfirst. - Use in deployment scripts when you know which keys will be stale after a code change.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Delete succeeds but data still served stale | Separate CDN/page cache layer | Purge CDN cache separately |
| Delete has no effect | Wrong group name | Use wp cache get to verify the key/group first |
Quick Reference
wp cache delete <key> # Delete from default group
wp cache delete <key> <group> # Delete from specific group
wp cache get <key> <group> # Verify deletion
wp cache flush # Full flush if targeted delete isn't enough
Next Steps
wp cache flush— clear all cache at once.wp cache get— inspect a key before deleting.wp cache set— re-prime the cache after deletion.