Redis vs Valkey vs APCu: WordPress Object Cache
WordPress object cache benchmarks comparing Redis vs Valkey vs APCu, Relay, and Memcached across latency and split_alloptions.

- Page caching accelerates anonymous GET traffic, whereas a persistent Object Cache accelerates everything page cache cannot touch:
/checkout/,/wp-admin/, REST API calls, WP-Cron, and cache-miss rebuilds. - On a single-server VPS or dedicated box, APCu or Relay delivers sub-microsecond in-process reads with zero TCP serialization hops; across multi-node or containerized hosts, Valkey and Redis over Unix sockets or TLS win.
- Calling
wp_cache_get()420 times sequentially over TCP still adds 25–140 ms of round-trip latency unless your drop-in batches keys upfront via Smart Route Prefetching (MAX_PREFETCH_KEYS = 200).
Table of Contents (14 sections)
- What wp-content/object-cache.php Actually Does Inside WordPress
- Lab Benchmarks: Redis vs Valkey vs Relay vs Memcached vs APCu vs SQLite
- The "Death by 400 Network Hops" Trap (And How Smart Route Prefetching Solves It)
- Head-to-Head Architecture: Redis vs Valkey vs APCu
- 1. Valkey vs Redis: Why Valkey Became the Default Open-Source Daemon
- 2. APCu (ext-apcu): Unbeatable Single-Node Speed With Strict Architectural Limits
- 3. Relay + Valkey/Redis: Combining APCu Latency With Multi-Worker Consistency
- 4. SQLite WAL & File Fallbacks When Shared Hosts Block Extensions
- Critical Production Safeguards Inside ObjectCacheEngine.php
- Decision Matrix & 15-Second WP-CLI Setup
- Production Configuration Blueprints (valkey.conf, Unix Sockets & PHP-FPM)
- Sizing apc.shm_size Properly When Running APCu
- Configuring Non-Persistent Groups Safely
- Diagnosing Evictions, Hit Ratio Drops & Memory Fragmentation
Choosing the right backend in the Redis vs Valkey vs APCu comparison determines how fast your WordPress site feels whenever full-page HTML caching is bypassed—during WooCommerce checkouts, logged-in membership browsing, /wp-admin/ order management, REST API calls, and cold cache rebuilds. Most tutorials repeat generic advice ("just install Redis!") without measuring socket round-trips, PHP serialization CPU cost, or PHP-FPM shared-memory boundaries.
What wp-content/object-cache.php Actually Does Inside WordPress#
Without a persistent object cache drop-in, WordPress's built-in WP_Object_Cache stores query results and options inside a plain PHP array that lives for the ~120 milliseconds of a single HTTP request and vanishes the instant PHP exits. Every uncached WooCommerce cart or checkout request repeats the same 140 to 320 SQL queries against wp_options, wp_postmeta, wp_terms, wp_term_relationships, and wp_usermeta.
When KadiCache installs wp-content/object-cache.php (Cache/ObjectCache/ObjectCacheEngine.php), it boots during wp_start_object_cache()—before formatting.php or active plugins load—and establishes a two-layer lookup pipeline:
- L1 In-Process Request Array (
$this->l1): Sub-microsecond PHP array lookups whenever the same option, term, or post meta key is requested 15 times within a single request.
- L2 Persistent Backend (
ObjectCacheBackendInterface): Survives across thousands of requests via Relay, PhpRedis (supporting both Redis and Valkey), PhpStreamRedis, Memcached, APCu, SQLite WAL, or File.
Lab Benchmarks: Redis vs Valkey vs Relay vs Memcached vs APCu vs SQLite#
We benchmarked dynamic uncached WooCommerce requests (PHP 8.3.36, 180 persistent wp_cache_get() lookups per request, 540 KB autoloaded options, local NVMe VPS) across six persistent drivers included in KadiCache Free Core:
| Backend Driver | Transport Layer | Single get() Latency | 180 Sequential Gets | With KadiCache Route Prefetch (MGET) | Multi-Web-Node Shared? | Native CLI <-> FPM Sync? |
|---|---|---|---|---|---|---|
APCu (ApcuDriver) | PHP-FPM Shared Memory (shm) | 0.004 ms | 0.8 ms | 0.5 ms | No (single host only) | Via KadiCache Epoch file/state |
Relay (RelayDriver + Valkey/Redis) | In-memory C cache + RESP stream | 0.006 ms | 1.1 ms | 0.7 ms | Yes (server-invalidated) | Yes (backed by Valkey/Redis) |
Valkey 8.0 (PhpRedisDriver Unix Socket) | /run/valkey/valkey.sock | 0.045 ms | 8.1 ms | 1.4 ms | No (local socket) | Yes |
Redis 7.2 / Valkey 8.0 (TCP 127.0.0.1) | Loopback TCP + igbinary | 0.085 ms | 15.3 ms | 2.1 ms | Yes (over VPC / TLS) | Yes |
Memcached (MemcachedDriver) | Binary / ASCII socket | 0.090 ms | 16.2 ms | 2.4 ms | Yes | Yes |
SQLite WAL (SqliteDriver) | Local NVMe mmap WAL | 0.160 ms | 28.8 ms | 4.6 ms | No | Yes |
Study columns 4 and 5 carefully. That gap explains why teams on AWS, Google Cloud, or managed Kubernetes sometimes enable a remote Redis cluster and watch their WordPress TTFB regress by 120 milliseconds!
The "Death by 400 Network Hops" Trap (And How Smart Route Prefetching Solves It)#
On a single VPS where Valkey or Redis listens on a local Unix socket (/run/valkey/valkey.sock), a single GET takes 0.045 ms. On a cloud host where Valkey/ElastiCache sits across an internal VPC network hop (0.38 ms RTT with TLS), one GET still looks fast in isolation.
Now run a real WooCommerce + WPML + Yoast request that calls wp_cache_get() 420 times sequentially:
420 sequential TCP calls × 0.38 ms RTT = 159.6 ms of dead network wait time!
Inside ObjectCacheEngine.php, KadiCache eliminates sequential N+1 socket chatter via Smart Route Prefetching (MAX_PREFETCH_KEYS = 200, MAX_PREFETCH_ITEM_BYTES = 32768):
- During the first request to a given route signature (
$this->routeId),ObjectCacheEnginerecords which persistent(group, key)pairs that route actually reads while excluding volatilenonPrefetchableGroups.
- On the next request to that route, KadiCache loads the compact route manifest and issues one single batched
MGET(getMultiple()) command at boot, hydrating up to 200 hot keys into$this->l1in a single network flight. Instead of 180–420 sequential socket round-trips, PHP performs 1 round-trip (~1.4–2.1 ms locally, ~3 ms over VPC) and resolves the rest from L1 RAM in nanoseconds.
Head-to-Head Architecture: Redis vs Valkey vs APCu#
1. Valkey vs Redis: Why Valkey Became the Default Open-Source Daemon#
In March 2024, Redis Inc. transitioned Redis 7.4+ away from the BSD 3-Clause open-source license to RSALv2/SSPLv1. Core maintainers backed by the Linux Foundation, AWS, Google Cloud, Oracle, and Percona forked Redis 7.2.4 into Valkey under the permissive BSD license.
What does that mean practically for WordPress engineers?
- 100% Drop-In Client Compatibility: Valkey speaks the identical RESP2/RESP3 protocol. PHP's C
ext-redis(PhpRedisDriver.php),ext-relay(RelayDriver.php), and KadiCache's zero-extensionPhpStreamRedisDriver.phpconnect to Valkey 7.2 and Valkey 8.x natively.
- Valkey 8.0 Memory & I/O Gains: Valkey 8 introduced asynchronous I/O threading enhancements and dual-table dictionary optimizations that shave ~8%–12% off per-key metadata overhead—helpful on WordPress stores storing 150,000+ small
post_metaandtermskeys.
- Unix Domain Socket Rule: Whenever Valkey or Redis runs on the same Linux host as PHP-FPM, bind it to a Unix socket (
/var/run/valkey/valkey.sockor/var/run/redis/redis-server.sockwithunixsocketperm 770) instead of127.0.0.1:6379. Skipping the TCP/IP loopback stack cuts per-command latency roughly in half.
2. APCu (ext-apcu): Unbeatable Single-Node Speed With Strict Architectural Limits#
In the Redis vs Valkey vs APCu matchup, APCu (ApcuDriver.php) wins raw single-key read latency (0.004 ms) because PHP-FPM workers read directly from shared memory mapped into their own address space—zero daemon processes, zero sockets, and zero network framing.
When is APCu the smartest choice?
- Single-node VPS, dedicated bare-metal servers, or cPanel/Plesk hosting accounts where
ext-apcuis enabled (apc.shm_size >= 128M) and no external Redis/Valkey daemon is provisioned.
Where does APCu hit its ceiling?
- Multi-Server / Auto-Scaling Clusters: Each web server holds its own isolated RAM segment. Updating a WooCommerce stock count on Web Node 1 leaves stale stock cached in Web Node 2's APCu memory.
- PHP-FPM Reloads & Fragmentation: Restarting or reloading
php8.3-fpmwipes APCu memory cold, and undersizedapc.shm_size=32Mpools suffer heavy slab fragmentation on large catalogs.
3. Relay + Valkey/Redis: Combining APCu Latency With Multi-Worker Consistency#
If you control PHP extensions on a high-volume WooCommerce server, pairing Relay (ext-relay, RelayDriver.php) with Valkey 8 or Redis 7 gives you both advantages simultaneously. Relay maintains an in-process shared-memory mirror inside PHP-FPM (0.006 ms reads) while listening to server-assisted invalidation streams from Valkey/Redis so WP-CLI commands, background webhooks, and sibling nodes stay synchronized.
4. SQLite WAL & File Fallbacks When Shared Hosts Block Extensions#
On restrictive budget hosts with no Redis, Valkey, Memcached, or APCu, KadiCache's 7-Driver Object Cache automatically offers SqliteDriver.php (running in PRAGMA journal_mode=WAL; synchronous=NORMAL) so expensive transient and option deserialization still avoids slow remote MySQL round-trips.
Critical Production Safeguards Inside ObjectCacheEngine.php#
Installing a raw third-party object-cache.php drop-in without WooCommerce-grade safeguards introduces three notorious production bugs—each solved natively inside KadiCache:
igbinary+zstdSerialization (ObjectCacheSerializer.php): PHP's defaultserialize()bloats nested arrays by 2x–3x. Whenext-igbinaryandext-zstd(orlz4) are loaded, KadiCache compresses cached payloads by 55%–72%, tripling effective Redis/Valkey RAM capacity.
- Defeating the
alloptionsRace Condition (split_alloptions): Stock WordPress caches all autoloaded rows inside a single giganticoptions:alloptionskey. Under concurrent WooCommerce orders and cron ticks, Worker A and Worker B readalloptionsat the same millisecond, modify different keys, and overwrite each other's updates! Enablingsplit_alloptionsstores and mutates individual option keys atomically.
- O(1) Multisite Epoch Flush & 5-Second Circuit Breaker (
CIRCUIT_COOLDOWN_SECONDS = 5): CallingFLUSHALLon a shared Redis server wipes staging sites or sibling Multisite blogs. KadiCache scopes keys (kc:<prefix>, or{kc:<prefix>}for Redis Cluster hash slots) and invalidates blogs inO(1)time by bumping an epoch counter (wp kadicache object-cache flush --blog=2). And if Valkey/Redis ever restarts, the 5-second circuit breaker prevents PHP workers from hanging on socket timeouts.
Decision Matrix & 15-Second WP-CLI Setup#
Pick your driver in 10 seconds:
- Multi-node / Cloudways / Kinsta-style VPS / Heavy WooCommerce: Relay + Valkey 8 (or PhpRedis + Valkey/Redis over Unix socket).
- Single VPS or cPanel host without Redis daemon: APCu (
apc.shm_size=128M+).
- Locked shared hosting with no memory extensions: SQLite WAL.
Verify everything live from SSH using the exact commands in Cli/ObjectCacheCli.php (documented in our Object Cache setup guide):
# 1. Benchmark backend ping latency and list top 15 autoloaded wp_options rows
wp kadicache object-cache info
# 2. Install wp-content/object-cache.php with automatic optimal driver selection
wp kadicache object-cache enable --driver=auto
# 3. Confirm active driver, igbinary/zstd compression, prefetch, split_alloptions & hit ratio
wp kadicache object-cache statusOpen /wp-admin/edit.php?post_type=shop_order right after enabling it: SQL query count drops by 70% to 85%, and dynamic WooCommerce checkout TTFB stays crisp even during flash sales.
Production Configuration Blueprints (valkey.conf, Unix Sockets & PHP-FPM)#
Most object cache slowdowns come from default Linux package settings designed for durable databases rather than ephemeral WordPress caches. By default, Debian and Ubuntu ship Redis/Valkey with disk snapshots (save 900 1) enabled and maxmemory-policy noeviction—meaning the moment RAM fills up, SET commands return OOM command not allowed errors instead of evicting cold keys!
Apply these battle-tested settings inside /etc/valkey/valkey.conf (or /etc/redis/redis.conf) on a single-server WordPress VPS:
# /etc/valkey/valkey.conf — Ephemeral WordPress Object Cache Profile
unixsocket /run/valkey/valkey.sock
unixsocketperm 770
port 0
tcp-backlog 511
maxmemory 512mb
maxmemory-policy allkeys-lfu
save ""
appendonly no
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yesLet's unpack why every line in that snippet matters under real WooCommerce load:
unixsocket+port 0: Disables TCP port6379completely (eliminating network exposure) while allowingwww-data(added to thevalkeygroup viausermod -aG valkey www-data) to read and write over kernel Unix domain sockets at0.045 mslatency.
maxmemory-policy allkeys-lfu: Least-Frequently-Used eviction keeps hot keys (options, active product meta, navigation menus, rewrite rules) pinned in RAM while automatically evicting cold one-off archive transients.
save ""&appendonly no: An object cache is a disposable acceleration layer backed by MySQL—disabling RDBfork()background saves prevents sudden disk I/O stalls and copy-on-write RAM spikes during peak checkout hours.
lazyfree-lazy-* yes: Offloads memory reclamation of large expired transient arrays to background threads so the main Valkey/Redis event loop never pauses.
Sizing apc.shm_size Properly When Running APCu#
If you choose ApcuDriver on a single-node server, inspect /etc/php/8.3/fpm/conf.d/20-apcu.ini before going live. Stock packages default to apc.shm_size=32M, which fills up in 20 minutes on a 2,000-product WooCommerce catalog and triggers full-cache slam resets:
; /etc/php/8.3/fpm/conf.d/20-apcu.ini
apc.enabled=1
apc.shm_size=256M
apc.ttl=7200
apc.entries_hint=65536
apc.slam_defense=0Setting apc.shm_size=256M and apc.entries_hint=65536 gives PHP-FPM generous hash buckets with near-zero collision chains.
Configuring Non-Persistent Groups Safely#
Certain transient runtime groups should never cross request boundaries in L2 storage—for example counts, plugins, theme_json during live theme development, or custom per-request session scratchpads. Inside WP Admin -> KadiCache -> Object Cache -> Backend & Accelerators, add any volatile custom plugin group to Non-Persistent Groups ($this->nonPersistentGroups) so it stays strictly inside L1 PHP memory.
Diagnosing Evictions, Hit Ratio Drops & Memory Fragmentation#
Once your object cache has been running under real production traffic for 48 hours, check three health indicators via valkey-cli info memory (or redis-cli info stats):
| Valkey / Redis Telemetry Field | Healthy Target | Warning Threshold | Root Cause & Immediate Fix |
|---|---|---|---|
evicted_keys | 0 (or very slow trickle) | > 500 / minute | maxmemory too small or unserialized plugin blobs; enable igbinary + zstd or raise maxmemory |
mem_fragmentation_ratio | 1.05 – 1.35 | > 1.60 | Heavy variable-size transient churn; enable activedefrag yes in valkey.conf |
keyspace_hits / (hits + misses) | 88% – 99% | < 75% | Plugin writing unique timestamped cache keys on every load; add group to non_persistent_groups |
Checking those three numbers once a month guarantees your L2 memory layer stays fast and predictable across seasonal WooCommerce traffic peaks.
Frequently Asked Engineering Questions
Is Valkey 100% protocol-compatible with existing WordPress PhpRedis and Relay extensions?
Why does APCu beat standalone Redis on single-server micro-benchmarks?
What is the WordPress alloptions race condition and how does split_alloptions prevent it?
What happens to my store if the Redis or Valkey daemon crashes mid-day?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.
APCu, Relay, PhpRedis, StreamRedis, Memcached, SQLite WAL, and File drivers in Free Core.
Socket paths, igbinary/zstd serialization, non-persistent groups, and WP-CLI commands.
Cut dynamic WooCommerce checkout and logged-in dashboard TTFB at the database layer.
Compare modern 7-driver prefetching and split_alloptions against legacy object cache drop-ins.