当前位置:网站首页>Cache avalanche, cache breakdown, cache penetration
Cache avalanche, cache breakdown, cache penetration
2022-07-18 02:35:00 【Amazing_ deron】
Cache breakdown
Cache breakdown is when hot data is requested in large quantities , This hot data key Out of date , Resulting in a large number of requests flooding into the database , Causing a surge in database pressure .
Solution : Get the distributed lock first when updating the cache after the cache expires , The thread that gets the lock can query the database and update the cached data , If the distributed lock acquisition fails , Prove that a thread is querying the database and updating , Try to get the lock again every second for three times , You can return to the status after three times : Data is being updated , Please try again later .
Cache penetration
Cache penetration refers to accessing data that does not exist in a database or cache , And users are constantly requesting , For example, visit id by -1 Or a very large data . The user at this time is likely to be the attacker , The attack will cause too much pressure on the database .
Solution : Add verification in the interface layer ,id<=0 Direct interception of data , Data that cannot be fetched in the cache , In the database, there is no access to , Set cache to key-null, Set the cache time smaller , Such as 30 second ( Prevent data from being unavailable under normal circumstances ), This prevents attackers from using the same id Violent attack .
Cache avalanche
Cache avalanche refers to the simultaneous expiration of batch data in the cache , And the number of queries is huge , Cause excessive pressure on database query and even downtime . Unlike cache breakdown , Cache breakdown is to query a piece of data concurrently , The cache avalanche is that different data has expired , Flooding into the database leads to a sharp increase in database pressure .
Solution : Cache expiration time is set randomly , Prevent the simultaneous expiration of a large amount of data at the same time .
Never expired data settings , Refresh regularly , When reading data
- There is no cache , Get the distributed lock first, and then query the database , Cache data
- There is a cache and it is not time to refresh , Direct read cache ;
- There is a cache and the refresh time has reached or exceeded , Read cache directly and refresh cache asynchronously , Update cache time ;
边栏推荐
- 03 key control LED
- Fragment (III) using fragment in viewpager
- 2022-04-20 unity entry 6 - light source components
- 可落地的DDD(7)-战术设计上的一些误区
- Want to go whoring for nothing, right? Enough for you this time!
- QT连接MySQL
- mysql show variables 查的是哪个表里面的数据?
- 2022-04-18 Unity入门3——脚本基础
- Fragment(四)常见问题
- navicat oracle怎么一个dmp文件导入两个不同的模式?
猜你喜欢

2022-04-21 unity foundation 1 - 3D mathematics

神奇宝贝 眼前一亮的 Jetpack + MVVM 极简实战

云呐-动环监控水浸绳,非定位水浸监测绳

CCF 202012-1 期末预测之安全指数

558. Intersection Quadtree: simple question récursive

07 printf重定向

Google recommends using sealed and remotemediator in projects

Google 推荐在 MVVM 架构中使用 Kotlin Flow

2022-04-18 Unity入门1——窗口布局

Practice of kotlin stateflow search function DB + network
随机推荐
Yunna computer room dynamic environment monitoring expansion scheme
2022 global developer salary PK: China ranks 19th, and using go language is the most profitable
any类型转换之谜
02 STM32CubeMX新建工程
爱奇艺加入龙蜥社区,携手打造多元化视频生态底座
[design topics] project summary of graduation design topics based on C51 single chip microcomputer - 500 cases
The difference between the elements dependencies and dependencymanagement
What are the main functions of Yunna dynamic ring monitoring system
Oracle 添加索引造成其他用户对此表的查询权限丢失
Apple and former design director Jony lve parted ways
2022-04-18 C# 第4篇——进阶
【综合笔试题】难度 2/5,递归运用及前缀和优化
How to encapsulate kotlin + Android databinding in a project
Using PostgreSQL on PostgreSQL 15_ FDW performs parallel commit of transactions
MySQL的隔离级别
2022-04-20 Unity入门7——物理系统之碰撞检测
Difference between idea smart checkout and force checkout
ESP8266 lua入门(二)
558. 四叉树交集 : 简单递归运用题
41: Chapter 4: develop file services: 2:fastdfs: (2): prepare two virtual machines, and then create two fastdfs basic environments; Configure tracker service on a virtual machine; Configure storage se