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
| Event | Action Needed |
|---|---|
After wp search-replace | wp cache flush |
After wp import | wp cache flush |
| After plugin activate/deactivate | wp cache flush |
After wp option update | Usually auto-cleared, but flush if stale |
| Debugging stale data | wp cache get KEY GROUP to inspect |
wp cache Subcommands at a Glance
| Command | Purpose |
|---|---|
wp cache type | Identify which cache backend is active |
wp cache flush | Clear all cached data |
wp cache get | Read a specific cached value |
wp cache set | Write a value to the cache |
wp cache add | Write only if key does not exist |
wp cache delete | Remove 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.
0means no expiration (backend-dependent). - Persistent vs non-persistent — Without a persistent cache plugin (Redis/Memcached),
wp cache flushhas no effect on the next real request — the in-memory cache is request-scoped.
Next Steps
wp cache flush— the most commonly used cache command.wp cache type— check if Redis or Memcached is active.