注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
发现这篇关于cache strategies文章讲的很好
https://codeahoy.com/2017/08/11/ ... oose-the-right-one/
我把要点记录下来了
Cache Aside
Application checks from cache, if hit, returns data. If miss, reads from DB, returns data to client and updates cache.
Use Case
read-heavy workload
Pros
resilient to cache failures
data model in cache can be different from DB
Cons
If write strategy is to write to DB directly, cache might be not consistent with DB (using TTL)
If consistency is required, either invalidate cache entry, or use write through.
Read Through
When cache miss, cache provider/library loads data from DB, populates cache and return data
Diff from Cache Aside
loading data is done by library or stand-alone cache provider
data model has to be the same as in DB
Use Case
read-heavy workload
Cons
cache miss for every first-time request (can do warming or pre-heating)
If write strategy is to write to DB directly, cache might be not consistent with DB (using TTL)
Write Through
Write to cache and then cache provider/library writes data to DB
Use Case
combining Read Through and Write Through gets all the benefits of read-through and we also get data consistency guarantee, freeing us from using cache invalidation techniques. (DynamoDB Accelerator uses this)
Write Around
Data is written to DB directly
Use Case
Write-around can be combine with read-through and provides good performance in situations where data is written once and read less frequently or never. For example, real-time logs or chatroom messages. Likewise, this pattern can be combined with cache-aside as well.
Write Back (Write Behind)
Application writes data to cache and immediatly ack, after some time, cache write data back to DB
Use Case
Good for write-heavy workloads
Resilient to DB failure
If batching or coalescing is supported, reduce overall write to DB
Redis use cache-aside and write-back to better absort spikes during peak load
Most relational DB storage engines (i.e. InnoDB) have write-back enabled by default
Cons
If cache failure, data maybe permanently lost
求米~ |