Conceptual
Login

When a Cache Is the Right Fix and When It Hides a Slow Query

A cache is the right rung when the query is already well written and well indexed, the same answer is requested far more often than the data changes, and stale answers are acceptable for a stated number of seconds. It is the wrong rung when it is hiding a query nobody has EXPLAINed, because you now have the original problem plus an invalidation problem, and the first cold cache after a deploy hands the full load to the database at once. Before caching, check the plan; after caching, watch the hit rate, because a cache with a low hit rate is pure added complexity.

Questions this Concept answers

  • Why is caching a query that nobody has examined described as acquiring two problems?