当前位置:网站首页>缓存雪崩和缓存穿透解决方案
缓存雪崩和缓存穿透解决方案
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
边栏推荐
- 100 important knowledge points that SQL must master: grouping data
- Oceanbase installation Yum source configuration error and Solutions
- Esp32-c3 introductory tutorial basic part ⑫ - mass production burning device configuration and serial number, NVS partition confirmation, NVS partition generation program, CSV to bin
- EMC surge
- SQL必需掌握的100个重要知识点:使用视图
- How to 'gracefully' avoid MySQL login prompt information in scripts
- Flutter start from scratch 008 form
- 科普达人丨漫画图解什么是eRDMA?
- Typescript readonlyarray (read only array type) details
- 100 important knowledge points that SQL must master: join table
猜你喜欢
"New digital technology" completed tens of millions of yuan of a + round financing and built an integrated intelligent database cloud management platform
R language view version R package view version
PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
[xi'anjiaotonguniversity] information sharing of the first and second postgraduate entrance examinations
国内首批!阿里云云原生数据湖产品通过信通院评测认证
关于IP定位查询接口的测评Ⅲ
“新数科技”完成数千万元A+轮融资,造一体化智能数据库云管理平台
科普达人丨漫画图解什么是eRDMA?
Esp32-c3 introductory tutorial question ⑨ - core 0 panic 'ed (load access fault) Exception was unhandled. vfprintf. c:1528
随机推荐
启明星辰集团运维安全网关(堡垒机)再次夺得榜首!
It's time for the kotlin coroutine to schedule thread switching to solve the mystery
数字化不是试出来,而是蹚出来的|行知数字中国 × 富士康史喆
数据库 自动增长
Jetpack Compose DropdownMenu跟随手指点击位置显示
100 important knowledge points that SQL must master: join table
Summer vacation study record
Alibaba cloud database represented by polardb ranks first in the world
微信表情符号被写入判决书,你发的每个 emoji 都可能成为呈堂证供
暑假学习记录
Uncover the whole link communication process of customer service im
Esp32-c3 introductory tutorial basic part ⑪ - reading and writing non-volatile storage (NVS) parameters
10天学会flutter DAY10 flutter 玩转 动画与打包
数据库连接池 druid
TypeScript ReadonlyArray(只读数组类型) 详细介绍
[leetcode 239] sliding window
Compression state DP bit operation
中移OneOS开发板学习入门
Understanding society at the age of 14 - reading notes on "happiness at work"
Key library function based on Hal Library