liveBook · Manning

Write-through caching

As explained in Learn Concurrent Programming with Go

Cache write-through is a cache update policy that immediately mirrors writes to the corresponding location in main memory.

Write-through caching mirrors a cache update to main memory immediately. It keeps memory current when one thread changes a shared variable, but other CPU caches may still hold stale copies. section 3.1

A shared-memory update can proceed as follows:

  • Thread 1 updates its cached copy of a variable. section 3.1
  • The update is mirrored to main memory, preventing a direct memory read from returning the older value. section 3.1
  • Other caches listen for bus update messages and either apply the update or invalidate their affected cache line. section 3.1
Figure 3.4 Updating shared variables in an architecture with caches

Follow the shared-variable update across caches and memory. section 3.1

How Learn Concurrent Programming with Go covers it

How deep it goes
Describes the update sequence and its stale-cache limitation, then connects the remedy to cache-coherency protocols.
Examples
Uses two threads updating and reading one shared variable across processor caches, supported by an architecture figure.
What it assumes
Assumes shared variables, processor caches, main memory, and bus communication across multiple CPUs.
What you can do after
Evaluate why mirroring writes to memory does not alone prevent stale values in other processor caches.
How it connects
Connects cache write-through with main memory, local CPU caches, cache invalidation, and cache-coherency protocols.

Also explained in

Compare how 3 books explain write-through caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.