Skip to main content

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

ContentCache?Why
Anonymous homepage✅ YesSame for all visitors
Blog posts✅ YesStatic for anonymous users
Static assets (CSS, JS, images)✅ YesNever changes per-user
Shopping cart❌ NoPersonalized per session
Checkout pages❌ NoContains user-specific data
Admin dashboard❌ NoSensitive and per-user
Logged-in user content⚠️ DependsVary by cookie or exclude

Rule Design Principles

  1. Cache anonymous pages aggressively — they are identical for all visitors
  2. Exclude carts, checkouts, and user dashboards — personalized content must not leak
  3. Vary cache by device or cookie only when necessary — excessive variance reduces hit rate
  4. Purge on content updates instead of using short TTLs everywhere

Common Patterns for WordPress + LiteSpeed Cache

The LiteSpeed Cache plugin handles most rules automatically:

RuleSetting
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 curl headers — never assume rules work without testing.

What's Next