Skip to main content

Cache Tools Overview

Overview

WordPress has a built-in object cache layer that stores temporary data in memory or an external cache backend (Redis, Memcached). WP-CLI's wp cache commands give you direct read/write/flush access to this cache from the terminal.

WordPress Cache Architecture

WordPress Request


Object Cache Layer (wp_cache_get / wp_cache_set)

├── Default: WP_Object_Cache (in-memory, per-request only)

└── Persistent: Redis / Memcached (survives across requests)

When the Object Cache Matters

EventAction Needed
After wp search-replacewp cache flush
After wp importwp cache flush
After plugin activate/deactivatewp cache flush
After wp option updateUsually auto-cleared, but flush if stale
Debugging stale datawp cache get KEY GROUP to inspect

wp cache Subcommands at a Glance

CommandPurpose
wp cache typeIdentify which cache backend is active
wp cache flushClear all cached data
wp cache getRead a specific cached value
wp cache setWrite a value to the cache
wp cache addWrite only if key does not exist
wp cache deleteRemove a specific cache key

Key Concepts

  • Groups — Cache is namespaced by group (e.g., posts, users, options). Always specify the correct group when targeting a specific key.
  • Expiration — Cache entries have a TTL in seconds. 0 means no expiration (backend-dependent).
  • Persistent vs non-persistent — Without a persistent cache plugin (Redis/Memcached), wp cache flush has no effect on the next real request — the in-memory cache is request-scoped.

Next Steps