← Concepts

阅读中文版本

Cache Warming Strategy

Cache warming pre-populates the cache with the working set before traffic arrives, so the first requests see a warm cache and the cold-start spike does not hammer the backing store.

performance

Definition

Cache warming is the practice of loading the expected working set into the cache before accepting traffic — at deploy time, at startup, or on a schedule — so that the first request after a cold start hits a populated cache rather than triggering a stampede of misses against the backing store.

Context and scope

Applied in deployments, restarts, and any cache whose cold-start miss pattern would overwhelm the backing store or violate a latency SLO.

Common misconceptions

  • Warming is just preloading the homepage — it is preloading the working set the traffic will hit, which may be the top N keys, the session store, or the index
  • A warm cache stays warm — eviction under memory pressure and key expiry can cold it; warming is a periodic or event-driven action

Anti-patterns

  • Warming the cache with every key, which takes longer than the cold start it was meant to avoid
  • Warming once at deploy and ignoring expiry, so the cache warms then cools as keys expire and the next cold start is unmitigated

Related concepts

Authoritative source

https://12factor.net/disposability

What it is

Cache warming is the practice of loading the expected working set into the cache before accepting traffic — at deploy time, at startup, or on a schedule — so that the first request after a cold start hits a populated cache rather than triggering a stampede of misses against the backing store. Applied in deployments, restarts, and any cache whose cold-start miss pattern would overwhelm the backing store or violate a latency SLO. Performance is a distribution, not a number: the tail determines user experience, and the mean hides the outliers that cause abandonment.

How it works

Measurement targets percentiles at the workload’s actual concurrency, not a single sequential run. The fast path is kept fast by deferring work that is not on it — lazy initialization, coalescing writes, avoiding allocation in hot loops. Profiling finds the bottleneck; micro-optimization without a profile optimizes the wrong thing. Constant factors matter, but algorithmic complexity dominates as scale grows.

When to optimize and pitfalls

Optimize when a measurement shows a concrete cost — latency budget burn, compute spend, user-visible jank. The pitfall is optimizing for the benchmark rather than the workload: a synthetic test that does not reproduce the production access pattern produces a local maximum that hurts globally. Another is trading memory for speed without accounting for the GC or eviction cost the extra allocation introduces.