Three patterns dominate cache design. Each trades write cost, read cost, and consistency differently. Pick based on your workload.
Cache Aside
App reads cache. Miss → read DB → populate cache. Most common. Simple. Writes go direct to DB; cache invalidated or expired.
Cache Aside
App reads cache. Miss → read DB → populate cache. Most common. Simple. Writes go direct to DB; cache invalidated or expired.
Write-Through
Every write goes to cache AND DB synchronously. Cache stays fresh. Write latency is DB latency + overhead.
Write-Behind
Write to cache; background writer flushes to DB. Fastest writes. Risk: cache crash before flush = data loss.
Read-Through
Cache Aside variant where cache library reads from DB on miss (not app). Cleaner separation.
Choose by workload
Read-heavy + tolerable staleness → Cache Aside. Strong consistency needed → Write-Through. Write-heavy + acceptable risk → Write-Behind.