mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-27 13:33:43 +00:00
Update 缓存.md
补一张时序图,说明先删除缓存再更新数据库时,读请求会把旧值写回缓存。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 85 KiB |
@@ -128,6 +128,8 @@ CDN 主要有以下优点:
|
||||
|
||||
删除缓存而不是更新缓存,是因为两个并发的写操作到达缓存的顺序可能和到达数据库的顺序不同,导致缓存中是旧值。先更新数据库再删除缓存,是因为反过来的话,删除缓存之后、更新数据库之前的读请求会把旧值重新写入缓存。
|
||||
|
||||
<div align="center"> <img src="pics/cache-aside-race.png" width="500px"/> </div><br>
|
||||
|
||||
这种模式仍然存在小概率的不一致,例如删除缓存失败。常用的补救措施:
|
||||
|
||||
- 为缓存设置过期时间作为兜底;
|
||||
|
||||
Reference in New Issue
Block a user