Write-through caching means…
Options
- Writes go to the cache only and never reach the DB
- Every write updates the cache and the database together (Correct option)
- Writes skip the cache and go straight to the DB
- The cache is cleared on every write
Answer
Every write updates the cache and the database synchronously
Why
With write-through, every time data is saved, the app writes it to the cache AND the database together.
The cache is always up to date, so reads are fresh. The cost is slower writes (two places).
Write-back (write-behind) writes to the cache first and to the database later: faster, but data can be lost if the cache crashes.
Remember
Write-through = write to cache and DB together.