Skip to content

How to use a cache well

Choose the right TTL, define an invalidation strategy, measure hit rate, and treat cache stampedes as a design problem, not an incident.

Using a cache without breaking correctness

  1. Define the TTL before the cache

    A cache without a TTL is a stale-data generator waiting for an incident.

  2. Decide how to invalidate

    TTL, write-through, write-behind, or explicit invalidation. Pick one; document it.

  3. Measure hit rate

    A cache with a 5% hit rate is an expensive way to slow down requests.

  4. Guard against stampedes

    When a popular key expires, N requests recompute it at once. Use locks, single-flight or jitter.