Cachingchapter 4 of 8 · 5 lessons
Cache Write Strategies
How and when writes propagate from cache to the database.
Your cache is now answering most reads. Then somebody edits a price.
For a moment there are two answers to the same question, and only one of them is true. What you do in that moment is the whole of this chapter. Write to both places and every write pays for both. Write to the cache and flush later, and a crash takes the difference with it. Skip the cache entirely and readers keep the old value until something removes it. Three answers to one question: when a write happens, does the copy get updated now, later, or never?
Lessons
5 in this chapter- Write-ThroughEvery write updates the cache and the database together, so reads never see a gap.2 min
- Write-BehindAcknowledge from the cache, flush to the database later, and accept the crash risk.2 min
- Write-AroundWrites skip the cache entirely, and only reads decide what deserves memory.3 min
- Cache ConsistencyBetween the write landing and the copy going, somebody is reading the old value. The question is who, and for how long.2 min
- Picking a CombinationRead and write strategies are chosen per data type, not once per system.3 min