Caching Strategies
Caching Strategies
Strategies
LAHIRU
LIYANAPATHIRANA
Page 2 of 22
Introduction
Caching is the process of storing frequently accessed
data in a temporary, high-speed storage layer—known
as a cache—to enable faster retrieval and reduce the
need to repeatedly fetch data from the original, slower
data source.
LAHIRU
LIYANAPATHIRANA
Page 3 of 22
LAHIRU
LIYANAPATHIRANA
Page 4 of 22
LAHIRU
LIYANAPATHIRANA
Page 5 of 22
LAHIRU
LIYANAPATHIRANA
Page 6 of 22
Caching Strategies
Caching strategies determine how data is stored in and
retrieved from a cache.
Read-Through
Write-Through
Write-Back (Write-Behind)
Write-Around
LAHIRU
LIYANAPATHIRANA
Page 7 of 22
LAHIRU
LIYANAPATHIRANA
Page 8 of 22
LAHIRU
LIYANAPATHIRANA
Page 9 of 22
LAHIRU
LIYANAPATHIRANA
Page 10 of 22
Read-Through
In this strategy, the cache acts as an intermediary
between the application and the primary data source.
LAHIRU
LIYANAPATHIRANA
Page 11 of 22
Read-Through
Use Cases
Well-suited for read-heavy workloads where the
application should be decoupled from direct data
access.
LAHIRU
LIYANAPATHIRANA
Page 12 of 22
Read-Through
Limitations
Cache misses may introduce additional latency, as
the cache must fetch and store the data before
returning it.
LAHIRU
LIYANAPATHIRANA
Page 13 of 22
Write-Through
In this strategy, data is written to both the cache and
the underlying database simultaneously.
LAHIRU
LIYANAPATHIRANA
Page 14 of 22
Write-Through
Use Cases
Ideal for applications that require strong
consistency between the cache and the database.
Write-Through
Limitations
Higher write latency, as every write operation must
update both the cache and the database. This can
impact performance under heavy write loads.
LAHIRU
LIYANAPATHIRANA
Page 16 of 22
Write-Back (Write-Behind)
In this strategy, data is written to the cache first, and
the update to the primary data source is delayed and
performed asynchronously.
LAHIRU
LIYANAPATHIRANA
Page 17 of 22
Write-Back (Write-Behind)
Use Cases
Ideal for write-heavy workloads where throughput
and performance are prioritized over immediate
consistency.
LAHIRU
LIYANAPATHIRANA
Page 18 of 22
Write-Back (Write-Behind)
Limitations
Risk of data loss if the cache fails before pending
writes are flushed to persistent storage.
LAHIRU
LIYANAPATHIRANA
Page 19 of 22
Write-Around
In the write-around caching strategy, write operations
bypass the cache and are written directly to the primary
data store.
LAHIRU
LIYANAPATHIRANA
Page 20 of 22
Write-Around
Use Cases
Suitable for scenarios where data is written once
and read infrequently or not at all.
LAHIRU
LIYANAPATHIRANA
Page 21 of 22
Write-Around
Use Cases
Higher latency on reads immediately after writes, as
the data won’t be in the cache and must be fetched
from the database.
LAHIRU
LIYANAPATHIRANA
Did You Find This
Post Useful?
LAHIRU
LIYANAPATHIRANA