Skip to main content

Object Cache (Redis)

Page cache serves full HTML for cacheable pages. Object cache is the next layer: it caches repeated results and expensive lookups in memory so dynamic requests (wp-admin, logged-in pages, cart/checkout, AJAX) do less database work.

When Redis Helps

ScenarioWhy Redis Helps
WooCommerce / LMS logged-in trafficMany repeated option/meta lookups and session-related reads
wp-admin is slowAdmin screens often run many queries and repeated lookups
Search and filtering are slowReduces repeated reads; still requires query optimization when needed

For cache-heavy static blogs, Redis may provide minimal visible benefit because most public requests never reach PHP/DB.

Setup Checklist (High-Level)

  1. Install Redis server.
  2. Set a memory limit and eviction policy.
  3. Enable a WordPress object cache drop-in (plugin creates wp-content/object-cache.php).
  4. Verify Redis connectivity and that WordPress reports "Object cache: enabled".
  5. Monitor hit/miss behavior over time.

Install Redis (Debian/Ubuntu)

install-redis.sh
sudo apt update
sudo apt install -y redis-server
sudo systemctl enable redis-server
sudo systemctl start redis-server

Verify:

redis-ping.sh
redis-cli ping

Expected:

redis-pong.txt
PONG

Configure Memory Safety

Set a max memory and an eviction policy so Redis behaves like a cache (evict) instead of pushing the server into OOM.

Config file paths vary by distro; common location is /etc/redis/redis.conf.

redis-cache-safety.conf
maxmemory 512mb
maxmemory-policy allkeys-lru

Restart:

restart-redis.sh
sudo systemctl restart redis-server

Basic Monitoring

redis-hit-miss-stats.sh
redis-cli info stats | grep -E 'keyspace_hits|keyspace_misses'

You can compute an approximate hit rate as:

hits / (hits + misses)

Common Mistakes

MistakeWhat HappensFix
No maxmemoryRedis grows until it competes with the OS and servicesSet maxmemory + eviction policy
Expecting Redis to fix slow queriesSlow queries stay slowUse slow query logs and indexing where needed
Remote Redis with high latencyAdds network delay to every lookupPrefer local Redis for object cache

What's Next