Five caching strategies
One exchange at a time. Read what changes, then explain it in your own words before moving on.
- Meet the components
- Follow the steps
- Compare an example
- Check your understanding
Five caching strategies
Watch who reads, who writes, and when the application gets its answer.
The application owns cache population. Writes need a deliberate invalidation policy.
How to use this example
Select Next step to read at your own pace, or Animate step to watch one exchange. Nothing advances until you choose.
What it means
Everyday example
State in this scenario
Inspect components & read every step
- Application
Software that carries out a task for its user.
Example: A timetable app looks up the next bus departure.
- Cache
A stored copy used to answer some requests faster. Copies can become outdated.
Example: An app reuses a recently fetched timetable instead of fetching it again immediately.
- Database
An organized store of records that software can read and update.
Example: A shop stores product quantities and order records.
Cache aside
The application owns cache population. Writes need a deliberate invalidation policy.
- Application Cache: GET key. The application checks for a cached value.
- Application Database: SELECT. On a miss, the application queries the database.
- Database Application: Value. The authoritative value returns to the application.
- Application Cache: SET + TTL. The application populates the cache for later reads.
Read through
The cache layer loads missing data on the application’s behalf.
- Application Cache: GET key. The application calls the cache layer.
- Cache Database: Load. The cache loader fetches the missing value.
- Database Cache: Value. The cache stores the result.
- Cache Application: Value. The application receives the value through the cache.
Write through
This model acknowledges only after the backing write succeeds.
- Application Cache: WRITE. The application submits a write through the cache.
- Cache Database: Persist. The cache layer writes the backing database.
- Database Cache: Commit OK. The backing write is confirmed.
- Cache Application: ACK. Only now is success returned.
Write around
Bypass cache on write; invalidate old entries to avoid stale reads.
- Application Database: WRITE. Write directly to the backing store.
- Application Cache: Invalidate. Remove any stale cached value for this key.
- Application Cache: Later GET. A later read misses the cache.
- Application Database: Read latest. The application retrieves the current value.
- Application Cache: Populate. Populate under the selected read policy.
Write back
A cache acknowledgement is not yet database durability.
- Application Cache: WRITE. The cache accepts the new value.
- Cache Application: Early ACK. The application gets an acknowledgement before the database write.
- Cache Database: Async flush. A later flush persists the dirty value; failure before durable storage is a risk.
- Database Cache: Confirmed. The cache can mark the value clean.
Fictional teaching trace. One moving dot represents an exchange, not a measured network capture.