Cache Rules
Learning Focus
By the end of this lesson you will know how to design cache rules that maximize hit rates without accidentally caching personalized or dynamic content.
Designing Good Cache Rules
The goal is simple: cache as much as possible, but never serve the wrong content to the wrong user.
What to Cache vs What to Exclude
| Content | Cache? | Why |
|---|---|---|
| Anonymous homepage | ✅ Yes | Same for all visitors |
| Blog posts | ✅ Yes | Static for anonymous users |
| Static assets (CSS, JS, images) | ✅ Yes | Never changes per-user |
| Shopping cart | ❌ No | Personalized per session |
| Checkout pages | ❌ No | Contains user-specific data |
| Admin dashboard | ❌ No | Sensitive and per-user |
| Logged-in user content | ⚠️ Depends | Vary by cookie or exclude |
Rule Design Principles
- Cache anonymous pages aggressively — they are identical for all visitors
- Exclude carts, checkouts, and user dashboards — personalized content must not leak
- Vary cache by device or cookie only when necessary — excessive variance reduces hit rate
- Purge on content updates instead of using short TTLs everywhere
Common Patterns for WordPress + LiteSpeed Cache
The LiteSpeed Cache plugin handles most rules automatically:
| Rule | Setting |
|---|---|
| Cache logged-out pages | ✅ Enabled by default |
Exclude /wp-admin/ | ✅ Enabled by default |
| Exclude WooCommerce cart/checkout | ✅ Enable WooCommerce integration |
| Purge on post update | ✅ Automatic |
| Cache REST API | ⚠️ Optional — evaluate per use case |
Verifying Cache Behavior
# Check if a page is cached
curl -sI https://example.com/ | grep "x-litespeed-cache"
# Test as different "users"
curl -sI -H "Cookie: wordpress_logged_in_abc=user1" https://example.com/
# Should show MISS (logged-in users bypass cache)
curl -sI https://example.com/
# Should show HIT (anonymous visitors get cached version)
warning
Caching logged-in or personalized pages unintentionally is a serious privacy and security risk. Always verify that user-specific content is excluded.
Key Takeaways
- Cache anonymous pages aggressively, exclude personalized content completely.
- Purge on content updates rather than using short TTLs.
- Verify cache behavior with
curlheaders — never assume rules work without testing.
What's Next
- Return to the Performance Optimization module for the complete overview.