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
| Scenario | Why Redis Helps |
|---|---|
| WooCommerce / LMS logged-in traffic | Many repeated option/meta lookups and session-related reads |
| wp-admin is slow | Admin screens often run many queries and repeated lookups |
| Search and filtering are slow | Reduces 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)
- Install Redis server.
- Set a memory limit and eviction policy.
- Enable a WordPress object cache drop-in (plugin creates
wp-content/object-cache.php). - Verify Redis connectivity and that WordPress reports "Object cache: enabled".
- 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
| Mistake | What Happens | Fix |
|---|---|---|
No maxmemory | Redis grows until it competes with the OS and services | Set maxmemory + eviction policy |
| Expecting Redis to fix slow queries | Slow queries stay slow | Use slow query logs and indexing where needed |
| Remote Redis with high latency | Adds network delay to every lookup | Prefer local Redis for object cache |