Three Ways to Handle a Write
A read cache is simple, but writes force a choice: when does the slow store get updated, and does the cache hold the new value? Three strategies cover most designs.
The Strategies
- Write through updates the cache and the backing store together on every write. Reads after a write are fast and the store is always current, but writes pay the full latency of both.
- Write back updates only the cache and marks the entry dirty, flushing to the store later. Writes are very fast but a crash before flush loses data.
- Write around writes straight to the store and skips the cache. The cache fills only on later reads, which avoids polluting it with data nobody reads again.
Choosing
Write through favors consistency, write back favors write throughput, and write around favors cache purity for read heavy workloads. Many systems blend them, for example write back with a durable journal so a crash can replay unflushed writes.
Key idea
Write through is consistent but slow, write back is fast but risks loss before flush, and write around keeps the cache clean for read heavy data.