π Database Queries: 100 β 5
Every page load = 100 database queries. Redis caches them in memory. Page generation: 800ms β 80ms.
What Is Object Caching?
WordPress queries database repeatedly for same data (user info, settings, post meta). Object cache stores results in RAM for instant retrieval.
π Without Object Cache
Page Load Request: 1. Query database for site options (10 queries) 2. Query for user data (5 queries) 3. Query for post meta (20 queries) 4. Query for taxonomies (15 queries) 5. Query for widgets (10 queries) ... 100+ total queries Every. Single. Page. Load. Result: Slow, DB overload
β With Redis Object Cache
First Page Load: - Queries database (100 queries) - Stores results in Redis (in RAM) Next 999 Page Loads: - Gets cached data from Redis (5 queries) - Database barely used Result: 10x faster, 95% less DB load
Setup Redis Object Cache
Step 1: Install Redis
# Ubuntu/Debian sudo apt-get install redis-server sudo systemctl start redis sudo systemctl enable redis # Verify redis-cli ping # Should return: PONG
Step 2: Install WordPress Plugin
Install “Redis Object Cache” plugin by Till KrΓΌss
Plugins β Add New β Search “Redis Object Cache” β Install & Activate
Step 3: Configure wp-config.php
// Add to wp-config.php (before 'That's all, stop editing!')
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_TIMEOUT', 1);
define('WP_REDIS_READ_TIMEOUT', 1);
define('WP_REDIS_DATABASE', 0);
// Optional: Password protection
// define('WP_REDIS_PASSWORD', 'your-redis-password');
Step 4: Enable Object Cache
Settings β Redis β Click “Enable Object Cache”
Status should show “Connected”
Performance Impact
| Metric | Without Redis | With Redis | Improvement |
|---|---|---|---|
| DB Queries per Page | 100-150 | 5-10 | 95% reduction |
| Page Generation Time | 800ms | 80ms | 10x faster |
| Server Load (CPU) | High | Low | 70% less |
| Concurrent Users | 50 | 500+ | 10x scale |
β οΈ Important Notes
- Flush cache: After theme/plugin updates, flush Redis cache
- Memory limit: Redis stores in RAM. Monitor memory usage
- Persistence: Configure Redis persistence for production
- Security: Set Redis password, bind to localhost only
“WooCommerce site was dying under 100 concurrent users. Enabled Redis object cache. Now handles 500+ users. Database queries dropped 95%. Server costs cut in half.”
