Skip to main content

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

ArgumentDefaultDescription
KEYCache key to delete
GROUPdefaultCache 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

CommandScopeUse When
wp cache delete KEYOne specific entryYou know exactly which key is stale
wp cache flushAll cached dataYou want a full clean slate

Best Practices

  1. Prefer targeted delete over full flush on production — flush causes a cache stampede where every request must re-fetch from the database simultaneously.
  2. Know the group — deleting from the wrong group is a no-op. Check plugin source or wp cache get first.
  3. Use in deployment scripts when you know which keys will be stale after a code change.

Troubleshooting

ProblemCauseFix
Delete succeeds but data still served staleSeparate CDN/page cache layerPurge CDN cache separately
Delete has no effectWrong group nameUse 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