WordPress object caching with an external backend — Redis or Memcached — eliminates redundant database queries by storing the results of wp_cache_get() calls in memory. Choosing between Redis and Memcached depends on your persistence, data-structure, and cluster requirements.
Problem: WordPress object cache hits are volatile — every PHP-FPM worker has its own in-memory cache that is discarded at request end, so the same expensive query runs once per worker per request instead of being shared.
Solution: Install a persistent object cache backend: Redis for sites that need data persistence and WooCommerce session storage (use the wp-redis drop-in), or Memcached for pure read caching without persistence requirements. Drop the object-cache.php file into wp-content/ and configure the connection in wp-config.php.
The comparison below covers installation, WordPress integration, persistence, eviction policies, and the key functional differences that matter for WordPress sites.
# ── REDIS ── # Install on Ubuntu/Debian sudo apt install redis-server php-redis # Enable in php.ini / conf.d: # extension=redis.so # Install the WP Redis drop-in (Automattic) composer require "automattic/wp-redis" # or via WP-CLI: wp plugin install redis-cache --activate wp redis enable # copies object-cache.php drop-in to wp-content/ # ── MEMCACHED ── sudo apt install memcached php-memcached # Install the WP Memcached drop-in: # Download object-cache.php from wordpress.org/plugins/memcached/ # Copy to wp-content/object-cache.php
Configure each backend in wp-config.php and understand the key differences:
<?php // ── REDIS wp-config.php ── define( 'WP_REDIS_HOST', '127.0.0.1' ); define( 'WP_REDIS_PORT', 6379 ); define( 'WP_REDIS_DATABASE', 0 ); // Redis supports 16 logical DBs define( 'WP_REDIS_PREFIX', 'helloadmin_' ); // namespace for multisite define( 'WP_REDIS_TIMEOUT', 1 ); // connection timeout in seconds define( 'WP_REDIS_READ_TIMEOUT', 1 ); define( 'WP_REDIS_MAXTTL', 3600 ); // cap all TTLs at 1 hour // ── MEMCACHED wp-config.php ── global $memcached_servers; $memcached_servers = [ 'default' => [ [ '127.0.0.1', 11211 ] ] ]; /* * REDIS vs MEMCACHED — quick reference: * * Feature Redis Memcached * ──────────── * Persistence Yes (RDB/AOF) No (RAM only) * Data structures Strings,Hash, Strings only * List,Set,ZSet * Pub/Sub Yes No * Cluster/HA Redis Cluster Built-in multi-server * Atomic operations Yes (MULTI/EXEC) CAS only * Memory efficiency Moderate Slightly better * WP multisite support Excellent Good * * Choose Redis if: you need persistence after restart, you use * WooCommerce sessions, or you want Pub/Sub. * Choose Memcached if: you already run Memcached, or you need * the absolute simplest memory-only cache. */ // Test the object cache from WP-CLI: // wp cache get <key> <group> // wp cache flush // wp redis status
NOTE: For most WordPress sites running WooCommerce, Redis is the better choice because it persists session data across restarts and supports WooCommerce's session handler. For purely static-content sites where cache loss on restart is acceptable, Memcached is slightly simpler to operate.