当前位置:网站首页>面试官:Redis&MySQL的三种缓存更新策略是怎样的?
面试官:Redis&MySQL的三种缓存更新策略是怎样的?
2022-07-19 16:22:00 【InfoQ】
- Cache Aside(旁路缓存)策略;
- Read/Write Through(读穿 / 写穿)策略;
- Write Back(写回)策略;
Cache Aside(旁路缓存)策略

- 先更新数据库中的数据,再删除缓存中的数据。
- 如果读取的数据命中了缓存,则直接返回数据;
- 如果读取的数据没有命中缓存,则从数据库中读取数据,然后将数据写入到缓存,并且返回给用户。


- 一种做法是在更新数据时也更新缓存,只是在更新缓存前先加一个分布式锁,因为这样在同一时间只允许一个线程更新缓存,就不会产生并发问题了。当然这么做对于写入的性能会有一些影响;
- 另一种做法同样也是在更新数据时更新缓存,只是给缓存加一个较短的过期时间,这样即使出现缓存不一致的情况,缓存的数据也会很快过期,对业务的影响也是可以接受。
Read/Write Through(读穿 / 写穿)策略
Read Through 策略
Write Through 策略
- 如果缓存中数据已经存在,则更新缓存中的数据,并且由缓存组件同步更新到数据库中,然后缓存组件告知应用程序更新完成。
- 如果缓存中数据不存在,直接更新数据库,然后返回;

Write Back(写回)策略

边栏推荐
- 运行selenium remotedriver时出现与NativeConstructorAccessorImpl.newInstance0错误的SessionNotCreatedException错误
- 安全合规,优惠不停!高品质出行服务,“享道”给你
- celery ValueError: not enough values to uppack(expected 3, got 0)
- 趣店罗敏,预制“韭菜”?
- 【软件测试】怎样的简历能让HR一眼就看上
- Emergency management department: solidly promote the major inspection of work safety and the "100 day action" of gas and self built houses
- Tiree Tree
- 离线底图瓦片,可用于Cesium加载使用
- How to open an account for agricultural futures trading?
- Solution to the problem of garbled code in visual code terminal
猜你喜欢
You can definitely use the carefully selected 100 soft test high-frequency interview questions before the interview
居安思危,安全先行 | 2022年7月中国数据库行业分析报告精彩概览!
开源开放,创新者赢,2022“科创中国”开源创新榜评选全面开启!
Table & Index bloat of PG
软件测试岗——面试时三大灵魂拷问,你受得住吗?
精挑细选的100道软测高频面试题,面试前你肯定用得上
Netease game Flink SQL platform practice
Cut rope
跟着苹果不赚钱,2万亿“果链”弃“果”拥“特”
Tiree Tree
随机推荐
软件测试与应用期末复习
VRRP Technology (detailed explanation)
历史上的今天:英特尔成立;万维网上传了第一张照片;eBay 分拆 PayPal
盒马“腰斩”,都怪侯毅话多?
原生表单提交数据
Markdown 初学者语法汇总
docker配置mysql,redis
分页存储管理方式
[software testing] how powerful are the new testers brought out in oneortwo months?
kubernates-1.24.2 (最新版) + containerd + nexus 尝鲜
The first bullet of FPGA Development: vivado software installation, development, use and engineering establishment
农产品期货交易怎么开户?
What if the cell length becomes wider when input appears in the cell?
光大银行分布式实战:国内最大缴费平台的数据库架构转型
为什么测试员和测试工程师的薪酬差距那么大?三分钟你全明白了
FreeRTOS personal notes - time slice support
CSDN定制T恤等你来拿,《新程序员》福利来袭!
实用技巧——小问题的一些解决办法
Draw sequence diagram with code! It's so cool
Emergency management department: solidly promote the major inspection of work safety and the "100 day action" of gas and self built houses