Write-Through
Writes pass through the cache
With Write-Through, the application sends a change to the cache, and the caching layer synchronously updates both its own value and the primary store. Success is returned only after the persistent write completes.
application
|
v
cache
|
+---- update cached value
|
+---- write ----> primary store
|
success
|
v
response
After the write, the cache already contains the new value
If every change goes through this path, the next reader should not first see an old copy left behind after a successful write. The cache is updated as part of the change operation.
This is convenient for data that is read again almost immediately after being written: there is no need to wait for the next cache miss to populate the cache with the new value.
Writes become more expensive
The main trade-off is write latency. The client waits not only for the cache update but also for the write to the primary store. If persistent storage is slow or temporarily unavailable, it directly affects the operation.
It is also important that changes do not bypass Write-Through. If another service or an administrative process modifies the primary source directly, the cache can be left with an old copy.