For a WordPress site that needs a persistent object cache, Redis is the right default. Not because it is faster — at the get-and-set traffic a WordPress request generates, the two backends are indistinguishable on a single host — but because the WordPress half of the decision is lopsided: the Redis drop-ins are actively maintained and the Memcached ones are not. Choose Memcached only when it is already installed, already serving something else on the box, and already wired to a drop-in you trust.
The more useful question is the one people skip: does this site need a persistent object cache at all? A brochure site whose traffic is anonymous and served from a full-page cache will see almost nothing, because PHP barely runs. A logged-in-heavy site — WooCommerce, a membership plugin, a busy wp-admin — is where the object cache changes the shape of the request.
What you’ll accomplish
- A clear answer on whether this particular site benefits from a persistent object cache, based on measurement rather than a Site Health nag.
- The backend chosen on the grounds that actually differ: drop-in maintenance, eviction behaviour, isolation, and what the host already runs.
- A drop-in installed, salted, and isolated so two sites cannot read or flush each other’s keys.
- An eviction policy and memory ceiling set deliberately rather than inherited from a package default.
- A before-and-after measurement you can show someone, with hit ratio and query count rather than a vague “it feels faster”.
Prerequisites
- WordPress 6.0 or newer. WordPress 6.6 changed the
wp_options.autoloadcolumn to accepton,off, andautoalongside the historicalyesandno, so the autoload query below has a version note. - WP-CLI available and able to bootstrap the site (
wp core versionreturns a number rather than an error). - Shell access on the host running PHP, plus the ability to edit
wp-config.php. - A Linux host. The
nc -q1flag used for Memcached stats is a GNU netcat option; the BSD netcat on macOS does not have it. - Either
redis-serverormemcachedreachable from the PHP host, and the matching PHP extension. Shared hosting often gives you a Redis instance you do not control — that changes several steps and is covered under boundaries at the end. - A staging copy. Installing a drop-in on production first is how you find out that a plugin caches something it should not have.
How it works
WordPress ships an object cache whether or not you install anything. WP_Object_Cache is an in-memory associative array populated during the request by wp_cache_set() and read by wp_cache_get(), keyed by a key and a group. Out of the box it is non-persistent: the array is built from scratch on every request and thrown away when PHP finishes. Its only job is deduplication within a single page load, which is why fifty calls to get_option( 'siteurl' ) cost one query, not fifty.
Dropping a wp-content/object-cache.php file into place replaces that class with one backed by an external store, and the array survives the request. The next visitor does not re-fetch the option, the post object, the term relationships, or the user meta — they come back over a socket instead of over SQL. Groups matter here: most are per-site, but groups registered through wp_cache_add_global_groups() (users, user metadata, site options) are shared across every site in a multisite network. The reference is WP_Object_Cache in the WordPress developer handbook.
The reason this does nothing for a brochure site is upstream of PHP entirely.
If the page cache answers the request, nothing downstream runs. The object cache only earns its keep on requests that reach PHP. That distinction, and the failure modes that come from confusing the two layers, are worked through in object cache versus page cache.
Once you have decided you need one, the backends differ in ways that are real but narrower than the marketing suggests:
- Persistence. Redis can write RDB snapshots or an append-only file, so a restart does not empty the cache; Memcached is memory-only and starts cold every time. For a cache role this matters less than it sounds, but it does affect the first minutes after a restart on a large site.
- Eviction. Memcached does LRU per slab class and that is the whole story. Redis offers a choice, and for a cache the choice is
allkeys-lru: every key is a candidate for eviction when memory fills. The default in many packages isnoeviction, which makes Redis return an error on writes once it is full instead of making room. The policies and their trade-offs are documented in Redis key eviction. - Memory layout. Memcached allocates memory in fixed-size slab classes, so the mixed value sizes WordPress produces — a 40-byte option next to a multi-megabyte
alloptionsblob — can leave one slab class starved while another sits half empty. Redis allocates per key. - Threading. Memcached is multithreaded; Redis executes commands on a single thread. On a WordPress workload this rarely decides anything, because the bottleneck is round trips and PHP, not backend CPU.
- Drop-in support. This is the one that actually decides it. The widely used, actively maintained WordPress drop-ins target Redis. Memcached drop-ins exist and work, but see far less traffic and far fewer fixes.
Step-by-step
-
Find out what the site does today. Before installing anything, read the current state.
wp cache type wp eval 'var_dump( wp_using_ext_object_cache() );' ls -l wp-content/object-cache.phpOn a site with no persistent cache you get
Default,bool(false), and a “No such file or directory” error. Anything else means a drop-in is already in place and you are debugging, not installing. -
Measure the baseline on a page that actually runs PHP. Query counts on an anonymous page tell you nothing if that page is served from the edge. Profile a logged-in or cart URL instead.
wp package install wp-cli/profile-command:@stable wp profile stage --url=https://example.com/my-account/The table reports
query_count,query_time,cache_hits,cache_misses, andcache_ratioper bootstrap stage. Write those numbers down:query_counton themain_queryandtemplatestages is the figure to beat. -
Check the autoloaded options first. A bloated
alloptionsblob makes every request pull the whole thing across the socket, and an object cache can make that worse rather than better.wp db query "SELECT ROUND(SUM(LENGTH(option_value))/1024) AS kb, COUNT(*) AS n FROM wp_options WHERE autoload = 'yes';"On WordPress 6.6 and newer, change the condition to
autoload IN ('yes','on','auto'). Under a few hundred kilobytes is healthy; several megabytes means you fix autoload before you add a cache backend. -
See what the host already has. The answer here often settles the Redis-or-Memcached question on its own.
php -m | grep -E '^(redis|memcached|memcache)$' redis-cli -h 127.0.0.1 -p 6379 ping echo -e 'version\r' | nc -q1 127.0.0.1 11211A working Redis answers
PONG. A working Memcached answersVERSION 1.6.21or similar. If neither responds, install the daemon and the matching PHP extension before continuing. If only Memcached responds and it is already serving another application, do not add a second daemon just to have Redis. -
Install the drop-in (Redis path). The plugin writes
wp-content/object-cache.phpfor you; do not copy it by hand.wp plugin install redis-cache --activate wp redis enable wp redis statusSuccess looks like
Status: Connected, aClient:line naming PhpRedis or Predis, andDrop-in: Valid.Drop-in: Invalidmeans some other file is sitting at that path. -
Salt and isolate the keys before any traffic hits it. This is the step people skip and then spend an afternoon on. Add to
wp-config.php, above the “That’s all, stop editing” line:define( 'WP_REDIS_HOST', '127.0.0.1' ); define( 'WP_REDIS_PORT', 6379 ); define( 'WP_REDIS_DATABASE', 3 ); define( 'WP_REDIS_PREFIX', 'shopprod:' ); define( 'WP_CACHE_KEY_SALT', 'shop.example.com:' ); define( 'WP_REDIS_MAXTTL', 86400 );WP_CACHE_KEY_SALTis the core-level constant that prefixes cache keys;WP_REDIS_DATABASEandWP_REDIS_PREFIXare the drop-in’s own isolation. Use all three when several installs share one daemon — two staging copies on one unsalted Redis will read each other’s user sessions, and a flush on one empties the other.WP_REDIS_MAXTTLcaps keys that would otherwise never expire. -
Set the memory ceiling and the eviction policy deliberately. A cache with
noevictionis not a cache; it is a store that starts failing writes when it fills.redis-cli config set maxmemory 512mb redis-cli config set maxmemory-policy allkeys-lru redis-cli config rewriteEach command returns
OK.config rewritepersists the change intoredis.confso a restart does not lose it — without it, the setting survives only until the daemon stops. Sizemaxmemoryagainst what the host can spare with PHP-FPM’s own footprint accounted for, not against total RAM. -
If you are staying on Memcached, know what you are choosing. Point the drop-in at the daemon, then watch the slabs rather than a single memory number.
memcached-tool 127.0.0.1:11211 displayThe output lists each slab class with its item size, item count, and eviction time. A class evicting every few seconds while others sit idle is slab starvation; the fix is restarting Memcached with a different growth factor, or moving to Redis.
Validate it works
Re-run the profile from step 2 against the same URL and compare like with like:
wp profile stage --url=https://example.com/my-account/
cache_ratio should climb on the second and subsequent runs and query_count should fall on the main_query and template stages. A ratio that does not move between runs means the drop-in is loaded but not persisting.
Confirm the backend is genuinely being written to, in the database you configured:
redis-cli -n 3 dbsize
redis-cli -n 3 --scan --pattern 'shopprod:*' | head -5
dbsize returns something like (integer) 4213 and the scan prints real keys carrying your prefix. An empty index alongside a healthy wp redis status means the drop-in is talking to a different index than you think.
Then read the hit ratio at the backend, which is the number that matters over days rather than seconds:
redis-cli info stats | grep -E 'keyspace_hits|keyspace_misses|evicted_keys'
redis-cli info memory | grep -E 'used_memory_human|maxmemory_human|maxmemory_policy'
Hits should outnumber misses by a wide margin on a warm site, and steadily climbing evicted_keys means the ceiling is too low for the working set. On Memcached the equivalent read is:
echo -e 'stats\r' | nc -q1 127.0.0.1 11211 | grep -E 'get_hits|get_misses|evictions'
Troubleshooting
wp cache typestill saysDefaultafter enabling the plugin. Either another plugin overwrotewp-content/object-cache.phpor OPcache is serving a stale copy. Runwp redis update-dropin, then restart PHP-FPM. The file’s first lines name the plugin that claims it.- Two sites returning each other’s data. Unsalted keys on a shared daemon. Set
WP_CACHE_KEY_SALTper install and give each one its ownWP_REDIS_DATABASE, then flush both. Verify withredis-cli -n 0 --scan | head -20that database 0 is not quietly holding everything. OOM command not allowed when used memory > 'maxmemory'in the PHP log. The eviction policy isnoevictionand Redis is full. Setallkeys-lruandconfig rewrite. If evictions continue at a high rate afterwards, raisemaxmemoryor shortenWP_REDIS_MAXTTL— the working set is larger than the ceiling.- Site got slower after enabling the cache. Usually a large
alloptionsvalue being serialised in and out on every request, or a plugin storing enormous transients. Re-run the autoload query from step 3 and look for single options in the hundreds of kilobytes. Fix the data, not the cache. SERVER_ERROR object too large for cacheon Memcached. The default item limit is 1 MB and something in WordPress exceeded it. Raising the limit with the daemon’s-Ioption is a workaround; the honest fix is finding the plugin storing a multi-megabyte value in a cache group.
When this is the wrong approach
A persistent object cache is not free, and there are sites where it is the wrong first move.
- Anonymous traffic behind a working page cache. If most requests never reach PHP, spend the effort on page-cache hit ratio instead. Adding Redis here produces a green Site Health check and no measurable change.
- A shared Redis you do not control. On shared hosting you often cannot set
maxmemory-policyor pick a database index. The cPanel and WHM specifics — per-account daemons, drop-in placement, isolation — belong in persistent object cache on cPanel rather than here. - A LiteSpeed stack. LSCache has its own object cache integration and its own way of wiring the drop-in, so the steps above are not the ones you want. Follow the LiteSpeed object cache guide instead.
- Covering for a plugin problem. A cache that hides a four-second query still leaves it taking four seconds on every miss and every cold start after a deploy. Profile first.
- Treating the cache as durable storage. Redis persistence is for warm restarts, not for data you cannot lose. Anything that must survive belongs in MySQL.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.