Cachingchapter 1 of 8 · 6 lessons
How Caching Works
Start here. What a cache is, why a database needs one, and where one can live.
Your app has one job. Someone opens a product page, your server asks the database for that product, and sends it back. It works, it is fast, and you ship it.
Then the app catches on. Last month you served ten thousand requests a day. This month it is a million. You have not changed a line of code, but pages that took 40 milliseconds now take 400, and the database is busy all afternoon.
Nothing is broken. Your database is doing exactly what you asked, a million times over. Most of those times it answers the same question about the same product and returns the same answer. That repetition is where a cache comes in.
Lessons
6 in this chapter- The Problem a Cache SolvesYour database is not doing hard work. It is doing easy work a million times, and charging full price for each one.2 min
- What a Cache IsA copy of your data kept somewhere faster, which you are allowed to lose.3 min
- Where Caches LiveFour places, from the user's phone to a server your whole fleet shares.3 min
- Reading From a CacheAsk the cache. If it is empty, ask the database and put the answer back.2 min
- Writing Through a CacheThe database is the truth, so every change has to decide what happens to the copy.2 min
- How Caches FailStale copies, full memory, everyone missing at once, and one key that gets all the traffic.3 min