Strategy

Cache Warming

A background workers proactively populating the cache. If we set the process regularly it can be called Scheduled Cache Refresh. The workers can be scale horizontally.

Read-Through

Read data from disk, then cache to memory.

Cache Aside

If read misses the cache, proceed Read-Through.

Write-Around

DB → return

Save data to disk only. The cache will be established by Cache Aside or Read-Through.

Write-Through

DB → Cache → return

Save data to both disk (first) and memory (second) in sync. Good for strong consistency, but slower.

Atomicity is ideal, but most system don’t support atomic writes across DB and cache.

Since the behaviour is “in sync”, the saving order does not matter in theory. But saving to disk first can lower the risk of data lost.

Write-Behind

Cache → return → DB

Save data to both memory (first) and disk (second) in async. Fast, but it could cause data lost, only suite for non-critical data.

aka: Write-Back

Is is useful for batching DB update: