liveBook · Manning

Write-through caching

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

Write-through caching is a caching technique that writes updated data synchronously to both the cache and the primary data store.

Write-through caching updates the primary data store and the in-memory cache when application data changes. Later reads go to the cache, keeping frequently requested data off the primary store. The cache sits between the application and its database. section 11.0

A basic application flow is:

  • Write an updated value to the data store and the cache. section 11.0
  • For a later read, request the value from the cache and return it to the client. section 11.0

Updating both places during the write helps keep cached values current. A variation fills the cache asynchronously through a background job, AWS Lambda function, or the application; that variation needs care because the cache update may not have finished when a read arrives. Unlike relying on a time-to-live (TTL) to expire old entries, this approach refreshes cached data when it changes. section 11.0 section 11.7

Leaderboard capacity

Suppose each team leaderboard takes 4 KB and the cache has 1 GB (1,048,576 KB) available. It can hold 262,144 such leaderboards. More teams than that create a capacity problem: a full cache may evict entries or stop accepting new data. Check whether the data you intend to write through will fit. section 11.0

Figure 11.2 Comparing the lazy-loading and write-through caching strategies

Compare where lazy-loading and write-through strategies place the cache update in the application's data flow. section 11.0

Test application performance with and without caching, and compare approaches before choosing one. Keeping data current is useful, but memory capacity remains a limit; decide how the application should handle entries that cannot remain in the cache. section 11.0

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Explains the write-and-read flow, asynchronous-fill option, and memory limit, but gives no write-through configuration steps.
Examples
Uses a team-leaderboard capacity calculation and a figure comparing lazy loading with write-through caching.
What it assumes
Assumes basic familiarity with application reads and writes while identifying the cache's position between application and database.
What you can do after
Evaluate/understand when updating a cache alongside a data store helps freshness and when cache capacity poses a risk.
How it connects
Connects write-through caching to lazy loading, cache expiration, cache eviction, and database load.

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 Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.