What is Caching?
Caching, told as a story about the memo board that answers frequent questions in advance.
Every guest asks the exact same question.Repeating the same answer every time slows the booth down.
Checking the back warehouse every single time takes forever.The more there is to check, the more those round trips add up.
Write the answer on the memo board in advance, and you can show it right away.No trip to the warehouse — the board alone is enough.
The board is fast — the trip to the warehouse is slow.The same answer takes very different amounts of time depending on where you look it up.
The board can still go wrong — bad answers or a sudden rush.A wrong answer gets copied to everyone, and a sudden rush slows that one moment down.
Caching = writing frequent answers on a memo board in advance, so you can show them right away without a trip to the back warehouse every time.
A cache is a storage layer that keeps a copy of frequently used data somewhere faster to reach. When the original changes, the cache must be updated or invalidated — getting that timing right is the hardest part of caching.
When grown-ups say it
- Cache
- The memo board in front of the booth. It holds frequent answers written in advance.
- TTL
- The expiry date written on the board. Once it passes, you check again and rewrite it.
- Cache invalidation
- Fixing the board because the answer changed. Forget to fix it in time, and the wrong answer stays.
- Cache hit / miss
- Whether the board already had it (hit) or not (miss). A miss still means a trip to the warehouse.
- Cache stampede
- Everyone rushing the board at the same moment. That one moment is actually slower, not faster.
- Cache layers
- Having more than one level, like a booth board and a gate board. The closest board gets checked first.
- Consistency
- Whether the board and the warehouse agree. Often it's fine if they sync up a little late. → the people who keep the park open
- Latency
- How long a guest waits for an answer. Using the board cuts this time way down. → the four gauges on the wall