
Caching Strategy: 5 Cache Layers to Make Your Site Lightning Fast
Want to know how your own site is doing?
Browser cache, server cache, object cache, CDN, and opcache – combined they make your website 10x faster.
Author: Kodulehehaldus
Cache = Memory
Cache stores a previously calculated result so it doesn't have to be recalculated the next time. A correctly configured cache turns a 3-second page into a 0.3-second one.
5 Cache Layers
1. Browser Cache
The visitor's browser stores files locally – they won't be reloaded on the next visit.
Cache-Control: public, max-age=31536000, immutable(1 year for static files)
2. CDN Cache
CDNs hold a copy of the server globally. The request only reaches your server if the CDN cannot provide a response.
3. Server-side Page Cache
Entire HTML pages are pre-generated and stored.
WordPress plugins:
- WP Rocket – premium, the best
- W3 Total Cache – free, powerful
- LiteSpeed Cache – for LiteSpeed servers
- WP Super Cache – official by Automattic
4. Object Cache (Redis/Memcached)
Database queries are stored in memory. Critical for active WordPress sites.
# Redis setup on Ubuntu
sudo apt install redis-serverWP plugin: Redis Object Cache.
5. PHP OPcache
A pre-compiled version of PHP code in memory. Standard equipment in PHP 7+.
Check: <?php phpinfo(); ?> → search for OPcache.
Recommended config:
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0 ; productionCache Invalidation
"There are only two hard things in Computer Science: cache invalidation and naming things." – Phil Karlton.
Rule: every content change invalidates the cache.
Automatic
- WordPress: WP Rocket/W3TC invalidates automatically
- After post update
- After comment
Manual
- Admin Bar → Purge cache
- Via API call (after deployment)
- CLI:
wp cache flush
Cache Strategy for Different Content
| Content | Cache Time | Strategy |
|---|---|---|
| Logo, CSS, JS | 1 year | Versioned URL (style.css?v=2) |
| Products (E-shop) | 1 hour | Invalidate after change |
| Homepage | 30 min | Invalidate after new post |
| Cart | 0 | NO cache |
| Admin | 0 | NO cache |
| API endpoint | varies | Per route |
Measurement
Before and after cache configuration:
| Metric | Without Cache | With Cache |
|---|---|---|
| TTFB (Time to First Byte) | 800ms | 80ms |
| Server CPU | 60% | 5% |
| Database Queries | 80/pg | 5/pg |
| Concurrent users (max) | 100 | 5000+ |
Common Mistakes
- Caching dynamic content (cart, login)
- Cache time too short (missing out on the main cache benefit)
- Old cache after update (user sees an old version)
- Same cache for different users (privacy risk)
- Same cache for mobile/desktop (responsive design solves this)
WooCommerce Specifics
For e-shops:
- ❌ Do not cache: cart, checkout, my-account
- ✅ Cache: products, categories, homepage
- ✅ Fragment caching for dynamic parts
Real-world Example
Client (WooCommerce, 5000 products):
- Before: TTFB 1.2s, page loads in 4.8s
- After (all 5 layers): TTFB 90ms, page loads in 0.8s
- 6x faster
Revenue increased by 18% over the next 30 days.
Summary
Caching is not optional in 2026. Every missing layer costs you customers. See also:
Our optimization service sets up all 5 layers in one week – guaranteed 50%+ speed improvement. Request a quote.
Sources
Join the newsletter
Once a month, practical tips on making your website faster, more secure and easier to find on Google and in AI search.
Author
Kodulehehaldus.com (Innov8it OÜ) – an Estonian web agency that builds, maintains and optimises websites.