Skip to main content
KadiCache
Engineering Journal · Architecture9 min read1,976 wordsVerified 2026-11-23

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.

Redis, Valkey, and APCu RAM object cache modules feeding a high-speed WordPress performance gauge
0.000 Layout Shift14 Sections✓ Verified
⚡ Executive Summary · 30-Second Spec100% Code-Verified
WP Admin Path
WP Admin -> KadiCache -> Object Cache
Measured Impact
68%–84% fewer SQL queries on uncached WooCommerce checkout & WP Admin
DevTools Proof Marker
wp kadicache object-cache status | wp-content/object-cache.php
  • 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)

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:

  1. 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.
  1. L2 Persistent Backend (ObjectCacheBackendInterface): Survives across thousands of requests via Relay, PhpRedis (supporting both Redis and Valkey), PhpStreamRedis, Memcached, APCu, SQLite WAL, or File.
FIG 01Persistent Object Cache engine with Smart Route Prefetching, race-free split_alloptions, and 5-second circuit breaker.Zoom 2x

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 DriverTransport LayerSingle get() Latency180 Sequential GetsWith KadiCache Route Prefetch (MGET)Multi-Web-Node Shared?Native CLI <-> FPM Sync?
APCu (ApcuDriver)PHP-FPM Shared Memory (shm)0.004 ms0.8 ms0.5 msNo (single host only)Via KadiCache Epoch file/state
Relay (RelayDriver + Valkey/Redis)In-memory C cache + RESP stream0.006 ms1.1 ms0.7 msYes (server-invalidated)Yes (backed by Valkey/Redis)
Valkey 8.0 (PhpRedisDriver Unix Socket)/run/valkey/valkey.sock0.045 ms8.1 ms1.4 msNo (local socket)Yes
Redis 7.2 / Valkey 8.0 (TCP 127.0.0.1)Loopback TCP + igbinary0.085 ms15.3 ms2.1 msYes (over VPC / TLS)Yes
Memcached (MemcachedDriver)Binary / ASCII socket0.090 ms16.2 ms2.4 msYesYes
SQLite WAL (SqliteDriver)Local NVMe mmap WAL0.160 ms28.8 ms4.6 msNoYes

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), ObjectCacheEngine records which persistent (group, key) pairs that route actually reads while excluding volatile nonPrefetchableGroups.
  • 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->l1 in 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.
FIG 02Configure Redis/Relay/SQLite parameters alongside Smart Route Prefetching, Atomic Split Alloptions, and zstd/igbinary compression.Zoom 2x

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-extension PhpStreamRedisDriver.php connect 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_meta and terms keys.
  • 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.sock or /var/run/redis/redis-server.sock with unixsocketperm 770) instead of 127.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-apcu is 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-fpm wipes APCu memory cold, and undersized apc.shm_size=32M pools 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:

  1. igbinary + zstd Serialization (ObjectCacheSerializer.php): PHP's default serialize() bloats nested arrays by 2x–3x. When ext-igbinary and ext-zstd (or lz4) are loaded, KadiCache compresses cached payloads by 55%–72%, tripling effective Redis/Valkey RAM capacity.
  1. Defeating the alloptions Race Condition (split_alloptions): Stock WordPress caches all autoloaded rows inside a single gigantic options:alloptions key. Under concurrent WooCommerce orders and cron ticks, Worker A and Worker B read alloptions at the same millisecond, modify different keys, and overwrite each other's updates! Enabling split_alloptions stores and mutates individual option keys atomically.
  1. O(1) Multisite Epoch Flush & 5-Second Circuit Breaker (CIRCUIT_COOLDOWN_SECONDS = 5): Calling FLUSHALL on 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 in O(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):

BASH
# 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 status

Open /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:

INI
# /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 yes

Let's unpack why every line in that snippet matters under real WooCommerce load:

  • unixsocket + port 0: Disables TCP port 6379 completely (eliminating network exposure) while allowing www-data (added to the valkey group via usermod -aG valkey www-data) to read and write over kernel Unix domain sockets at 0.045 ms latency.
  • 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 RDB fork() 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:

INI
; /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=0

Setting 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 FieldHealthy TargetWarning ThresholdRoot Cause & Immediate Fix
evicted_keys0 (or very slow trickle)> 500 / minutemaxmemory too small or unserialized plugin blobs; enable igbinary + zstd or raise maxmemory
mem_fragmentation_ratio1.05 – 1.35> 1.60Heavy 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?
Yes. Valkey forked from Redis 7.2.4 under the Linux Foundation BSD license and speaks the exact same RESP2/RESP3 wire protocol. KadiCache PhpRedisDriver, RelayDriver, and PhpStreamRedisDriver connect to Valkey 7.2 and 8.x over TCP or Unix sockets with zero configuration changes.
Why does APCu beat standalone Redis on single-server micro-benchmarks?
Because APCu reads directly from PHP-FPM shared memory (shm) inside the same OS process group—zero socket syscalls and zero RESP wire framing. However, APCu cannot be shared across multiple web servers, resets whenever PHP-FPM restarts, and isolates CLI memory from FPM workers.
What is the WordPress alloptions race condition and how does split_alloptions prevent it?
By default, WordPress packs every autoloaded option into one monolithic cached array called alloptions. When two concurrent requests update different options simultaneously, one worker can overwrite the other worker updated array. KadiCache split_alloptions stores and mutates options granularly to prevent that race.
What happens to my store if the Redis or Valkey daemon crashes mid-day?
Inside ObjectCacheEngine.php, KadiCache enforces a 5-second circuit breaker (CIRCUIT_COOLDOWN_SECONDS = 5). Instead of hanging every visitor on repeated socket timeouts, WordPress falls back cleanly to in-request L1 memory and MySQL until the daemon recovers.
Verified WordPress Architecture · Architecture
Apply these exact optimizations on your WordPress or WooCommerce site in 2 minutes.
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

Cache/ObjectCache/ObjectCacheEngine.phpCache/ObjectCache/Drivers/PhpRedisDriver.phpCache/ObjectCache/Drivers/RelayDriver.phpCache/ObjectCache/Drivers/ApcuDriver.phpCli/ObjectCacheCli.php
Connected Topical Cluster · Continue Deepening Your Setup