Cache basics — hit ratio, TTL, eviction
A cache's hit ratio isn't a setting — an entry earns hits only if it's read again while the cache still holds it. What fits caps the ratio, a TTL trades freshness for hits, and when the cache is full an eviction policy guesses what to drop.
12 minEasyStation: Cache basics: hit ratio, TTL, evictionMembers lesson
Membership isn’t open yet. The free lessons are open — 16 of them.
- Memory vs disk vs network
- Cache basics: hit ratio, TTL, eviction
- Cache-aside
- Read-through & write-through
What you'll be able to do
- 1Explain what sets a cache's hit ratio — whether the same data is asked for again while the cache still holds it — and work out the load it leaves on the store behind.
- 2Explain how a TTL trades freshness against hit ratio, and what happens when an entry expires.
- 3Size a cache against the hot set its reads fall on, and choose an eviction policy — LRU, LFU or random — for the access pattern.
Inside the lesson
- steps
- 10
- questions
- 8
- simulations
- 3
You guess first, then run the system and see if you were right.
Step 1 · The setup
At the last stop, Pixel's team saw that memory answers in nanoseconds while the database's disk takes milliseconds — so a copy of busy data in memory, a cache, pays.
Pixel's feed API answers 200 feed reads a second, each a query on the photo database. Readers ask for 1,000 different feeds, but not evenly: the busiest 200 draw 80% of the reads.
The team puts a cache in front of the database, with room for 200 feeds. Once warm, it holds the feeds read most.
Steps 2–10 are for members