Labs

Cache hit ratio

Skew the traffic, size an LRU cache and add a TTL: watch the hit ratio, the average latency and the origin load move.

TTL
1/49

A warm cache with 8 slots. Press play: each step is one request for one key.

This stream—0 hits of 0Measured above66%200,000 requests
Hit ratio66%measured, after warm-up
Average latency17.5 msno cache: 50 ms
Origin load34%of requests · 3.0× less than no cache
Top 1% of keys62%share of all requests

skewed, s = 1.0 · uniform (s = 0) · x: cache size (keys, log) · y: hit ratio

Where the average latency comes from

hits × cache663 µs
misses × origin16.8 ms

A cache holding 5.0% of the keys serves 66% of the reads; with uniform traffic the same cache would serve 4.9%. Skew is what lets a small cache work.

How it's calculated · assumptions

avg = hit × cache + miss × origin = 0.663 × 1 ms + 0.337 × 50 ms = 17.5 ms · origin load = requests × (1 − hit)

Past 90% every point counts: 90% → 99% hits cuts origin traffic 10× and the average latency from 5.9 ms to 1.49 ms.

Toy stream (illustrative): 8 slots and a 160-key catalog, so the same cache share and skew as your settings; warmed up first, no TTL, durations not to scale. #r is the r-th most popular key: watch the hot ones stay. The red-edged slot is the least recent one, the next to be evicted.

Simulated in your browser: 200,000 seeded requests at an assumed 1,000/s (200 s); the first 100,000 warm the cache and the hit ratio is measured on the rest. LRU eviction; a TTL counts from the miss that filled the key (cache-aside), hits don't extend it, and an expired copy keeps its slot until evicted. A key's first request is always a miss, so with a huge catalog even an infinite cache stays below 100%. Formulas from the caching and CDN concepts.