When not to cache

Caching is a tool, not a strategy. Some reads should never be cached because the cost of staleness is higher than the cost of a database query. Knowing when to leave the database alone is a mark of experience.

Do not cache anything per-user unless you are sure the cache is scoped per-user too. Do not cache real-time data like stock prices, live sports scores, or bank balances. Do not cache anything a customer uses to make a buying decision they cannot reverse. Do not cache writes, ever. Do not cache the results of a query with sensitive data in the key itself.

Scope the key. users:42:dashboard instead of users:dashboard. That way, two users never see each other's data, and you can invalidate only one user's cache when their data changes. The pattern is the same: prefix plus identifier. It just has one more segment.

Validation checklist: Watch the cache in action

Loading practice…

Quiz: Quiz

Loading practice…

Checkpoint: Caching and optimization checkpoint

Loading practice…