Codele / System design
Caching
Walking to the library for every fact is slow. Keep the recent ones in a notebook on your desk. Pick a list of requests and watch the notebook save time.
- A cache keeps recent answers close, so you need not fetch them again from the slow place.
- A hit means the answer was in the cache (fast). A miss means it was not, so you fetch it and store a copy.
- A cache is small, so when it is full something must go. Least recently used removes the item not touched for longest.
- Caches shine when the same things are asked for again and again. A list of all-different requests gets no help.
- The hard part is stale data: the copy in the cache can be out of date, so caches need a time limit or a refresh rule.
Loading the playable lesson…