Avoiding repeated work.
WHAT TO CACHE
Expensive computations Frequently repeated queries External responses that change rarely Rendered fragments
WHAT NOT TO CACHE
Data that must always be current Personal data, in a shared cache
WHAT THE STRATEGIES ARE
- Read through: check the cache, fall back to the source
- Write through: update both on write
- Write behind: update the cache, persist later
WHAT THE HARD PROBLEM IS
Invalidation.
WHAT TO DECIDE FOR EACH ENTRY
How stale it may be What invalidates it
WHAT TO PREFER WHERE POSSIBLE
Expiry, which is simple and self-correcting.
WHAT TO BE CAREFUL WITH
Many entries expiring simultaneously, causing a surge on the source Caching failures Cache keys that collide
WHAT TO DO ABOUT THAT FIRST ONE
Vary expiry slightly between entries.
WHAT TO MEASURE
Hit rate, and whether load actually reduced.
WHY
A cache with a poor hit rate adds complexity for nothing.
WHAT TO ENSURE
That the system works correctly when the cache is empty or unavailable.