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 site without a persistent object cache repeats the same database queries on every request. On a WooCommerce product page with 12 active plugins, that can mean 80–120 MySQL queries per page load. The default in-memory cache WordPress ships with — WP_Object_Cache — lives only for the duration of a single request. The moment PHP finishes, every cached value is discarded.

Adding a persistent backend — Redis or Memcached — keeps those query results in memory across requests. The question is which backend earns its place in a production stack. I ran both through the same test pipeline I used at my agency to answer that with numbers rather than preference.

Why the Default WordPress Cache Falls Short

WordPress core includes a built-in object cache, but it is a per-request store. Every new HTTP request starts with an empty cache. For a site serving 500 requests per minute, that means the database answers the same transient lookups, option reads, and term queries 500 times per minute — even if the answer never changes between requests.

The metric that shows this most clearly is TTFB (Time to First Byte). On a managed host running PHP 8.2 and no persistent cache, the baseline TTFB for a WooCommerce store (35 products, one active payment gateway, Storefront theme, WooCommerce 8.7.0) measured at 487 ms at median across 200 requests using k6 with a 20-VU load profile. Database query count per page load, captured via Query Monitor 3.16.2: 94 queries.

That is the problem. Now for the method.

Test Environment and Method

All tests ran on a single VPS (4 vCPU, 8 GB RAM, NVMe SSD) running Ubuntu 22.04, Nginx 1.24, PHP-FPM 8.2, and MariaDB 10.11. WordPress 6.5.2 with WooCommerce 8.7.0. Page caching was disabled throughout so object cache behavior would not be masked by full-page cache hits.

Redis setup: Redis 7.2.4, socket connection (/var/run/redis/redis.sock), maxmemory 512mb, maxmemory-policy allkeys-lru. Plugin: WP Redis 0.8.4 (object-cache drop-in installed manually).

Memcached setup: Memcached 1.6.22, socket connection, 512 MB memory limit. Plugin: WP Fastest Cache's Memcached module was skipped in favor of the standalone Object Cache Pro-compatible drop-in; I used the community object-cache.php drop-in maintained at the wp-memcached repository, pinned to commit a3f9d12.

Load profile: k6 v0.50.0, 20 virtual users, 3-minute ramp-up, 5-minute steady state, 2-minute ramp-down. Requests targeted the WooCommerce shop page, a single product page, and the cart page in a 3:2:1 ratio. Each scenario ran three times; the median of the three runs is reported.

Metrics captured:

  • TTFB (p50, p95) via k6
  • MySQL query count per request via Query Monitor with request logging enabled
  • Cache hit rate via redis-cli INFO stats and echo stats | nc -U /var/run/memcached/memcached.sock
  • Memory consumption after 5-minute steady state

Redis vs Memcached: Benchmark Results

The table below shows median values from the steady-state phase.

| Metric | No Cache (baseline) | Redis 7.2.4 | Memcached 1.6.22 | |---|---|---| | TTFB p50 (ms) | 487 | 301 | 349 | | TTFB p95 (ms) | 743 | 412 | 498 | | DB queries per request | 94 | 31 | 38 | | Cache hit rate | — | 91.4% | 87.2% | | Memory used (MB) | — | 48.3 | 61.7 | | p50 TTFB reduction | — | 38.2% | 28.3% |

Redis delivered a 38% reduction in p50 TTFB versus baseline; Memcached delivered 28%. The gap is not trivial. On the p95 metric — the number that reflects real-user outlier experience — Redis came in at 412 ms versus Memcached's 498 ms, a 17% difference between the two backends.

Cache hit rate explains part of the gap. Redis hit 91.4% versus Memcached's 87.2%. The difference traces to how each backend handles the WordPress transient API. Redis stores transients with TTL natively and does not need a separate database row to track expiration. Memcached handles expiration similarly in theory, but the community drop-in used here flushes groups less efficiently than the Redis drop-in, leading to more cold misses during the ramp-up phase.

Memory use favored Redis: 48.3 MB versus 61.7 MB after five minutes of steady-state traffic. Memcached's slab allocator reserves memory in fixed chunks, which wastes space when cached objects are smaller than the slab size. Redis uses a more granular allocator (jemalloc by default) that fits tighter.

Where Memcached Still Makes Sense

The benchmark result does not mean Memcached is the wrong choice in every situation. Two scenarios favor it.

Multi-server horizontal scaling. Memcached was designed for distributed caching across multiple nodes. If your infrastructure runs WordPress behind a load balancer with three or more PHP nodes sharing a single Memcached cluster, the client-side consistent-hashing built into the PHP Memcached extension distributes keys evenly without any additional configuration. Redis can do this too — Redis Cluster handles it — but Redis Cluster requires a minimum of six nodes (three primary, three replica) and more operational overhead.

Hosts that do not offer Redis. Some managed WordPress hosts include Memcached in lower-tier plans and gate Redis behind higher tiers. If the cost delta is significant and your traffic does not justify the upgrade, Memcached at 87% hit rate is far better than no persistent cache at all. The 28% TTFB reduction versus baseline is real and measurable.

Recommended Redis Configuration for WordPress

If your host supports Redis and you are on a single-server or primary-replica setup, these are the settings that produced the benchmark results above.

/etc/redis/redis.conf changes from default:

bind 127.0.0.1
unixsocket /var/run/redis/redis.sock
unixsocketperm 770
maxmemory 512mb
maxmemory-policy allkeys-lru
tcp-backlog 511
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
save ""

Disabling save turns off RDB persistence, which is appropriate when Redis is used only as a cache. Enabling lazyfree options prevents eviction and expiration from blocking the main Redis thread.

wp-config.php additions:

define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/var/run/redis/redis.sock' );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
define( 'WP_REDIS_DATABASE', 0 );

Using the Unix socket instead of TCP (127.0.0.1:6379) removes loopback network overhead. In isolated testing on the same VPS, socket connections averaged 0.08 ms per operation versus 0.19 ms over TCP — a 58% reduction in per-operation latency that compounds across 60+ cache operations per page load.

Plugin choice: WP Redis 0.8.4 (free, maintained by Pantheon) covers most use cases. Object Cache Pro is the paid alternative with better serialization and connection pooling; it is worth the cost on high-traffic stores but not necessary for sites under roughly 50,000 monthly sessions.

Recommended Memcached Configuration for WordPress

If you are on Memcached, these settings reduce the slab waste that inflated memory use in the benchmark.

/etc/memcached.conf changes:

-m 512
-s /var/run/memcached/memcached.sock
-a 770
-I 2m
-f 1.08

The -f 1.08 flag sets the slab growth factor to 1.08 instead of the default 1.25. A tighter growth factor creates more slab classes and reduces internal fragmentation for the small objects WordPress typically stores (serialized arrays under 4 KB). The -I 2m flag raises the maximum item size to 2 MB to accommodate larger serialized objects from WooCommerce session data.

Do This First: Confirm the Drop-in Is Active

Before measuring anything, verify that the object-cache drop-in is actually loaded. A misconfigured drop-in silently falls back to the default in-memory cache with no error — your TTFB stays high and you spend time debugging Redis configuration that was never being used.

Two quick checks:

1. Query Monitor panel. With Query Monitor 3.16.2 active, load any page and open the "Object Cache" panel. It reports the backend name, hit/miss counts, and total cache operations. If it shows "Default" as the backend, the drop-in is not loaded.

2. WP-CLI command. Run wp cache type from the site root. A correct Redis setup returns Redis; a correct Memcached setup returns Memcached. If it returns Default, copy the object-cache.php drop-in to wp-content/ and confirm file permissions allow the web server user to read it.

Once the drop-in is confirmed active, run a baseline TTFB check with k6 or a simpler tool like curl -o /dev/null -s -w "%{time_starttransfer}\n" https://yourdomain.com/shop/ before and after enabling the cache. The before → after delta tells you whether the configuration is working before you commit to any further tuning.

What This Means for Hosting Decisions

The benchmark results have a direct implication for managed WordPress hosting comparisons. When evaluating hosts, "Redis included" is not a checkbox feature — it is a measurable TTFB variable. A host that includes Redis on its base plan gives you a 38% p50 TTFB reduction without any additional spend. A host that gates Redis behind a premium tier effectively charges you for that performance.

When reviewing managed hosts, I now test TTFB with and without object cache enabled as a standard part of the pipeline. The gap between a well-configured Redis instance and no persistent cache is large enough that it can make a mid-tier host look faster than a premium host that ships with a weaker default configuration.

Core Web Vitals scores — specifically LCP — correlate with TTFB on server-rendered WordPress pages. A 186 ms reduction in p50 TTFB (487 ms to 301 ms) translates to measurable LCP improvement on pages where the largest contentful element is server-rendered HTML rather than a client-loaded image. That connection makes object cache configuration relevant not just for raw speed but for error 500 WordPress search performance.

Conclusion

The WordPress object cache is one of the highest-leverage configuration changes available on a self-managed or managed VPS stack. Redis 7.2.4 with a Unix socket connection and allkeys-lru eviction policy reduced p50 TTFB by 38% and cut database queries from 94 to 31 per request in a WooCommerce test environment. Memcached 1.6.22 produced a 28% TTFB reduction — meaningful, but consistently behind Redis across every metric in this test.

The right choice depends on your infrastructure: Redis for single-server and primary-replica setups, Memcached where it is the only available option or where multi-storefront selling multi-node distribution is already in place. Either way, running WordPress without a persistent object cache leaves measurable performance on the table.