当前位置:网站首页>缓存雪崩和缓存穿透解决方案
缓存雪崩和缓存穿透解决方案
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
边栏推荐
- Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
- Qt嵌入子Qt程序窗口到当前程序
- 数据库 级联操作
- 100 important knowledge points that SQL must master: using subquery
- H3C switch emptying configuration
- 【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
- 记一次ViewPager + RecyclerView的内存泄漏
- "New digital technology" completed tens of millions of yuan of a + round financing and built an integrated intelligent database cloud management platform
- Compression state DP bit operation
- 8 lines of code to achieve quick sorting, easy to understand illustrations!
猜你喜欢

Methods and usage of promise async and await

win10 R包安装报错:没有安装在arch=i386

对象映射 - Mapping.Mapster

Alibaba cloud lifeifei: China's cloud database has taken the lead in many mainstream technological innovations abroad

The jetpack compose dropdownmenu is displayed following the finger click position

暑假学习记录

EMC surge

R language view version R package view version

记一次ViewPager + RecyclerView的内存泄漏

Wechat Emoji is written into the judgment, and every Emoji you send may become evidence in court
随机推荐
如何通过GDB分析Native Crash
The life, working principle and application of electrochemical oxygen sensor
Esp32-c3 introductory tutorial basic part ⑫ - mass production burning device configuration and serial number, NVS partition confirmation, NVS partition generation program, CSV to bin
高通发布物联网案例集 “魔镜”、数字农业已经成为现实
How to 'gracefully' avoid MySQL login prompt information in scripts
【小程序实战系列】小程序框架 页面注册 生命周期 介绍
Compression state DP bit operation
The first China Digital Collection conference will be held soon
据说用了这个,老板连夜把测试开了
Introduction to China Mobile oneos development board
SQL必需掌握的100个重要知识点:联结表
【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
国内首批!阿里云云原生数据湖产品通过信通院评测认证
Introduction to game theory
win10 R包安装报错:没有安装在arch=i386
Qualcomm released the "magic mirror" of the Internet of things case set, and digital agriculture has become a reality
SQL必需掌握的100个重要知识点:插入数据
ESP32-C3入门教程 基础篇⑪——Non-Volatile Storage (NVS) 非易失性存储参数的读写
Esp32-c3 introductory tutorial basic part ⑪ - reading and writing non-volatile storage (NVS) parameters
Kongsong (ICT Institute) - cloud security capacity building and trend in the digital age