Lesson 1 of 16
12. Caching: The Basics

The picture to keep in your head

3 min read+10 XP

Every question below is answered twice: first in the kitchen, so you can picture it, then in the system, so you know exactly how it works. Each answer ends with a memory code to lock it in.

The picture to keep in your head

You keep milk in your fridge so you don't walk to the supermarket every time you want tea. The fridge is small, fast and right next to you. The supermarket has everything, but every trip is slow.

Our running example: an online grocery app. A user opens the product page for milk. The app needs the milk's name, price and photo.

KitchenSystem
SupermarketDatabase (the original, the "source of truth")
FridgeCache
You, making teaThe app, handling a user's request
A label on a box in the fridgeA key
Use-by dateTTL (time to live)

the fridge and the supermarket, mapped to the cache and the database.

Figure: the fridge and the supermarket, mapped to the cache and the database.