Cache layers
- HTTP cache — browsers and proxies cache responses based on Cache-Control headers
- CDN — edge nodes cache static assets and even dynamic responses
- Application cache — Redis or Memcached store query results and computed data
- OPcache — PHP caches compiled bytecode
- DB query cache — some databases cache query results (removed in MySQL 8+)
Invalidation
The hardest part of caching is deciding when data is stale. Two strategies: TTL (time to live) — simpler, but data may be outdated; event-based invalidation — more precise, but harder to implement.