当前位置:网站首页>缓存雪崩和缓存穿透解决方案
缓存雪崩和缓存穿透解决方案
2022-06-30 11:06:00 【全栈程序员站长】
缓存雪崩和缓存穿透 缓存雪崩:简单的说就是缓存失效,原本该访问缓存的数据直接访问数据库,从而造成数据库和内存压力大,严重的可能导致数据库宕机、服务器崩溃。 解决方案: 1.使用分布式锁或者对列控制读数据库写缓存的线程数,保证这有一个个线程进行操作。缺 点降低了系统的吞吐量 2.redis中的key 失效时间尽量设置分布均匀 3.使用mq来解决缓存雪崩效应。 当大量请求访问redis中没有值,把查询参数投放在消息队列,消费者接收到消息查询数据库得到结果使用同步方式返回给生成者。 消息中间件具有缓存消息的功能 4.设置一级二级缓存。如果一级缓存失效的时候,让访问请求二级缓存,需要注意二级缓存失效时间最好比一级缓存失效时间长一点。 5.如果是某一台redis服务器宕机,可以搭建redis主备 进行高可用。
缓存上一级还可以设置服务降级、隔离、容错、熔断等防止雪崩。—-springcloud服务治理框架,服务容错机制hystrix
缓存穿透: 缓存的流程:用户查询数据的时候先查询缓存,如果缓存没有,在查询数据库,把查询得到的结果放入一份在缓存中,下次在查询的时候如果缓存中有数据,就直接返回给客户端从而降低数据库的压力。 缓存穿透:用户查询的数据在数据库中没有,从而缓存中也没有用户查询数据的结果。如果有人恶意攻击使用这个查询数据一直进行查询,导致数据库压力增大。
解决方案:1.把查询的空结果也缓存一份。这样就可以简单有效的避免绕过缓存直接查询数据库。 2.同时也可以单独设置个缓存区域存储空值,对要查询的key进行预先校验,然后再放行给后面的正常缓存处理逻辑
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100801.html原文链接:https://javaforall.cn
边栏推荐
- The first China Digital Collection conference will be held soon
- 数字化不是试出来,而是蹚出来的|行知数字中国 × 富士康史喆
- ESP32-C3入门教程 问题篇⑨——Core 0 panic‘ed (Load access fault). Exception was unhandled. vfprintf.c:1528
- R language de duplication operation unique duplicate filter
- SQL必需掌握的100个重要知识点:创建和操纵表
- 华三交换机清空配置
- What is a wechat applet that will open the door of the applet
- 暑假学习记录
- Handler source code analysis
- 脚本中如何'优雅'避免MySQL登录提示信息
猜你喜欢
![[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations](/img/06/df5a64441814c9ecfa2f039318496e.jpg)
[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations

8 lines of code to achieve quick sorting, easy to understand illustrations!

国内首批!阿里云云原生数据湖产品通过信通院评测认证

Multiparty Cardinality Testing for Threshold Private Set-2021:解读

dplyr 中的filter报错:Can‘t transform a data frame with duplicate names

Alibaba cloud database represented by polardb ranks first in the world

【西安交通大学】考研初试复试资料分享

The reasoning delay on iphone12 is only 1.6 MS! Snap et al. Analyzed the transformer structure latency in detail, and used NAS to find out the efficient network structure of mobile devices

Filter error in dplyr: can't transform a data frame with duplicate names

导致系统性能失败的10个原因
随机推荐
19年来最艰难的618,徐雷表达三个谢意
线代(高斯消元法、线性基)
R language de duplication operation unique duplicate filter
从开源项目探讨“FPGA挖矿”的本质
[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations
Database cascading operation
华三交换机清空配置
Alibaba cloud lifeifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
R语言去重操作unique duplicate filter
HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
Summer vacation study record
100 important knowledge points that SQL must master: using stored procedures
Is the golden cycle of domestic databases coming?
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
OceanBase 安装 yum 源配置错误及解决办法
[leetcode 16] sum of three numbers
Livedata source code appreciation III - frequently asked questions
【无标题】
Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
Retest the cloud native database performance: polardb is still the strongest, while tdsql-c and gaussdb have little change