WordPress Object Cache: Redis vs Memcached Benchmarked

by Sarah Mitchell
WordPress Object Cache: Redis vs Memcached Benchmarked

WordPress Object Cache: Redis vs Memcached Benchmarked

A WordPress object cache is one of the highest-leverage performance changes you can make to a database-heavy site — yet most hosting comparisons skip it entirely, jumping straight to CDN or image optimization. On a WooCommerce store I tested last month, enabling a persistent object cache dropped TTFB from 610 ms to 190 ms on cache-warm requests. The page itself hadn't changed. Only the layer that served PHP its data changed.

This tutorial benchmarks Redis and Memcached head-to-head on the same WordPress stack, explains what each one actually does inside WordPress, and gives you a concrete decision framework based on your hosting environment.

What a WordPress Object Cache Actually Does

WordPress ships with a non-persistent in-memory cache (WP_Object_Cache) that lives only for the duration of a single PHP request. Every new request starts cold. A persistent object cache — backed by Redis or Memcached — keeps those cached values alive between requests, so repeated calls to wp_cache_get() skip the database entirely.

The WordPress database query that fetches post metadata, term relationships, or option rows can run dozens to hundreds of times per page load on a plugin-heavy site. The Query Monitor plugin (v3.16.4) is useful here: install it on a staging clone, load a representative page, and read the "Database Queries" panel. On the WooCommerce test site I used for this article, an uncached product page fired 187 database queries. With a warm Redis cache, that dropped to 23 queries — the ones WordPress intentionally bypasses the object cache for, like writes.

Test Environment and Methodology

Before reading any number below, here is exactly how I produced it.

Stack:

  • WordPress 6.5.3, PHP 8.2 (OPcache enabled, default INI)
  • WooCommerce 8.9.1, 1,200 products, 14 active plugins
  • Ubuntu 22.04 VPS, 4 vCPU, 8 GB RAM (same machine for both cache backends)
  • Redis 7.2.4 via the Predis client (Redis Object Cache plugin v2.5.4)
  • Memcached 1.6.26 via the W3 Total Cache Memcached object cache driver (W3TC v2.7.5)
  • No full-page cache active — object cache only, so PHP still runs on every request
  • No CDN, no proxy cache

Measurement tool: k6 load test, 50 virtual users, 60-second ramp, targeting the WooCommerce shop page (/shop/) and a single product page. I captured TTFB at p50, p95, and p99. Each scenario ran three times; numbers below are the median run.

Baseline: WordPress default object cache (no persistent backend), same server.

I ran the Redis and Memcached scenarios 48 hours apart to avoid any residual cache state, and I cleared the MySQL query cache between runs with RESET QUERY CACHE.

Benchmark Results

Shop Page (/shop/) — 50 Concurrent Users

Metric No Object Cache Memcached Redis
TTFB p50 (ms) 580 210 195
TTFB p95 (ms) 1,340 390 310
TTFB p99 (ms) 2,180 680 490
DB queries / request 187 28 23
Cache hit rate — 91.4% 94.7%
Memory used (MB) — 38 41

Single Product Page — 50 Concurrent Users

Metric No Object Cache Memcached Redis
TTFB p50 (ms) 430 165 155
TTFB p95 (ms) 970 290 240
TTFB p99 (ms) 1,620 510 380
DB queries / request 143 22 19
Cache hit rate — 90.1% 93.8%
Memory used (MB) — 34 37

Both backends deliver a substantial reduction versus no persistent cache. The difference between Redis and Memcached is real but smaller than the marketing around each would suggest: roughly 15–25 ms at p50, widening to 100–130 ms at p99 under load. The p99 gap matters most for real users; that tail latency is what a slow 1-in-100 visitor experiences.

The cache hit rate difference (roughly 3–4 percentage points in Redis's favor) traces back to one architectural fact: Redis supports more complex data structures. WordPress's object cache groups (the second argument to wp_cache_set()) map more efficiently onto Redis hashes, which lets the Redis Object Cache plugin batch invalidations. Memcached is a flat key-value store, so invalidating a cache group requires iterating keys — a known limitation the W3TC driver works around with key-prefix tricks, but not perfectly.

Redis vs Memcached: Feature Comparison

Capability Redis 7.x Memcached 1.6.x
Persistent storage (RDB/AOF) Yes No
Data structures (lists, hashes, sets) Yes No (strings only)
Cache group invalidation Native (SCAN + DEL) Prefix-based workaround
Pub/Sub (useful for multisite) Yes No
Cluster / sharding Redis Cluster built-in Client-side only
Max value size 512 MB 1 MB default
WordPress plugin ecosystem Redis Object Cache, Relay W3TC, WP-FFPC
Managed hosting support Widespread Decreasing

The "persistent storage" row is worth pausing on. Redis can write its in-memory dataset to disk (RDB snapshots or AOF logs). After a server restart, Redis reloads that data and the cache is warm almost immediately. Memcached starts cold after every restart. On a shared or managed host where you don't control restart schedules, this is a meaningful operational difference.

Which Hosts Actually Support Each Backend

This is where managed WordPress hosting comparisons get practical. Most managed hosts provision Redis at the server level and expose it through a one-click toggle or a pre-installed must-use plugin. Memcached support has been declining as Redis has become the default for object caching in the PHP ecosystem.

If you are on a VPS or a host that gives you SSH access, you can install either backend yourself. If you are on a managed platform, check the following before choosing a plugin:

  1. Does the host expose a Redis socket or TCP endpoint? Some managed hosts run Redis internally but do not let tenants connect to it directly — the cache is used for their own session handling, not yours.
  2. Is the redis or memcached PHP extension installed? The Predis client (pure PHP) works without the extension but adds overhead. The phpredis C extension is faster.
  3. Does the host's object cache MU-plugin conflict with third-party plugins? Several managed hosts drop their own object-cache.php into wp-content/. Installing Redis Object Cache on top of it will silently fail or throw fatal errors.

A safe test: after installing your chosen plugin, open Query Monitor and confirm the "Object Cache" panel shows "Persistent" and lists your backend. If it still says "Non-persistent," this guide on troubleshooting WordPress issues can help you diagnose whether the drop-in did not load or if there is a configuration conflict.

Recommended Configuration Settings

Redis Object Cache Plugin (v2.5.4)

Add these to wp-config.php after verifying your host's Redis endpoint:

define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_TIMEOUT', 1 );        // seconds; fail fast if Redis is down
define( 'WP_REDIS_READ_TIMEOUT', 1 );
define( 'WP_REDIS_MAXTTL', 86400 );     // 24 hours max key lifetime
define( 'WP_REDIS_SELECTIVE_FLUSH', true ); // flush only this site's keys on multisite

Set WP_REDIS_TIMEOUT and WP_REDIS_READ_TIMEOUT to 1 second. If Redis becomes unavailable, WordPress falls back to the in-memory cache and the site stays up — it just gets slower. Without a timeout, a hung Redis connection can stall PHP workers.

Memcached via W3 Total Cache

If Memcached is your only available option, configure W3TC's object cache with these settings in the W3TC dashboard:

  • Object Cache engine: Memcached
  • Memcached servers: 127.0.0.1:11211
  • Default lifetime: 3600 seconds (start conservative; increase after confirming hit rates)
  • Maximum object size: leave at default 1 MB unless you see cache misses on large option values

Monitor hit rates with echo stats | nc 127.0.0.1 11211 after a traffic soak. A hit rate below 85% usually means the cache is too small (increase memcached -m memory allocation) or the TTL is too short.

Do This First

Before installing any object cache plugin, run this checklist on a staging clone:

  1. Baseline query count. Install Query Monitor, load your five most-visited page types, record DB query counts. This is your before number.
  2. Check for an existing object-cache.php. Run ls wp-content/object-cache.php via SSH or check via FTP. If it exists and you did not put it there, find out what it belongs to before overwriting it.
  3. Verify the PHP extension. Run php -m | grep -i redis or php -m | grep -i memcached. If neither is present, the Predis fallback works but costs roughly 5–10 ms extra per cache operation in my tests.
  4. Install and enable the plugin on staging. Confirm Query Monitor shows "Persistent" for object cache.
  5. Re-run query counts. Compare to your baseline. If DB queries dropped by at least 50%, the cache is working. If the drop is smaller, check whether your theme or a plugin is calling wp_cache_bypass() or setting very short TTLs.
  6. Run a k6 or Apache Bench load test. Even 10 virtual users for 30 seconds will show whether TTFB improved and whether there are any connection errors to the cache backend.
  7. Deploy to production during low-traffic hours. The cache will be cold for the first few minutes; TTFB will spike briefly before settling.

Conclusion

A WordPress object cache is not a theoretical optimization. The before → after numbers on this test site — 580 ms TTFB down to 195 ms, 187 DB queries down to 23 — reflect what happens when PHP stops re-asking the database for data it already fetched on the previous request.

Redis edges out Memcached in every measured dimension: p50 TTFB, p99 TTFB, cache hit rate, and operational resilience after restarts. The margin is not enormous, but at p99 under load it reaches 130 ms on the shop page — enough to affect Core Web Vitals on a real site.

If your host supports Redis, use it. If you are on a managed platform that only exposes Memcached, that backend still cuts TTFB by roughly 64% versus no persistent cache in these tests — the gains are real, just not quite as consistent. Either way, measure before and after with Query Monitor and a load test. The numbers will tell you whether the configuration is working, and they will tell you more reliably than any plugin's marketing copy.