当前位置:网站首页>Three cache methods and principles
Three cache methods and principles
2022-06-22 22:44:00 【Autumn leaf flower】
Cache aside
The system usually bypasses the cache
- If the query cache service exists, it returns , There is no query database
- There is an update cache in the database , Return the data , There is no update cache with null( The period of validity ), Prevent cache penetration
- After updating the database , to update \ Delete cache

Application scenarios :
- It is applicable to business scenarios with frequent queries ( Configuration information , Login user information ...)
advantage : Cache miss query database , It belongs to lazy loading mode (Lazy Loading)
shortcoming :
1. Not hit, , The operation process is complex , Check cache , Database search , Update cache
2. When data is updated frequently , Frequent cache updates , Cache effect is reduced
3. It can easily lead to inconsistent data , Generating dirty data
Cache aside cache 4 Two update methods
The first is to update the cache first , Update the database ;
The second method is to delete the cache first , Update the database ;
The third is to update the database first ; Updating cache ;
The fourth is to update the database first ; Deleting cache ;
The probability of inconsistency caused by the four update caches is as follows :
( Cache update delay Far below Database update )
The first one is > The second kind > The third kind of > A fourth
It is recommended that the application system use the third , The fourth way is to update the cache , If the requirements for data consistency are strict ,
It is recommended to use the second method 4 Kind of ( After optimizing and updating the database , Delete the cache immediately , Then pause for a few seconds to delete )
Cache aside In cache mode Cache breakdown , Cache penetration , Cache avalanche solution
Cache breakdown :
The query cache does not , The database has ; In case of a large number of concurrent queries , This will increase the pressure on the database , Causes the system to be unavailable
Solution :
Cache preheating ; When querying the database key Add mutex lock ; The cache does not set a validity period ( Don't suggest )
Cache penetration :
The query cache does not , The database doesn't either ; In a large number of concurrent cases , This will increase the pressure on the database , Causes the system to be unavailable
Solution :
Verify the query data ; Bloon filtration ( Cuckoo filter ); When querying the database key Add mutex lock , When the database does not exist , Update cache to null And set the validity period of a few seconds ;
Cache avalanche
When querying the cache , A large amount of data is out of date , Query a large number of hits to the database , This will increase the pressure on the database , Causes the system to be unavailable
Solution :
Add a random time to the cache validity ; Hotspot data does not have a valid period ; Hot data is distributed among different servers
Read/Write through
Cache instructions
Use the cache as the primary data source , And the database is transparent to the application , Read 、 The task of updating the database is entrusted to the cache agent

Application scenarios
Many queries , Less updates , Scenarios with high data consistency
advantage : High data consistency , Quick query
shortcoming : For frequently written scenarios , Cause a delay , Performance degradation
Write behind
Cache usage
Use caching as a reliable data source , Only write to the cache every time ; The database operation is asynchronous

Application scenarios
Write more , Less read application scenarios ( stock , Advance order )
advantage : Update database asynchronously , Reduce database pressure ; Strong anti concurrency ability , Completely dependent on cache
shortcoming : Easy data inconsistency , Risk of missing data
边栏推荐
- Talk about SQL profile again: can I fix the execution plan?
- Mysql database DML operation exercise
- The method of making videos of knowledge payment system support m3u8 format playback
- Practice brings true knowledge: the strongest seckill system architecture in the whole network is decrypted. Not all seckills are seckills!!
- Developing salary management system based on C language course paper + source code and executable EXE file
- MySQL functions
- What are the indicators, dimensions and models in Business Intelligence BI data warehouse?
- Codeup longest palindrome substring
- The xinjietu x70s has been listed for 87900 times and has leapfrogged the class in space safety. It is worthy of being a 7-seat SUV of the National University of China
- [path planning] week 1: Path Planning open source code summary (ROS) version
猜你喜欢

5分钟快速上线Web应用和API(Vercel)

There are 15 necessary knowledge points for the second level cost engineer before the exam! I wish you success!

The xinjietu x70s has been listed for 87900 times and has leapfrogged the class in space safety. It is worthy of being a 7-seat SUV of the National University of China

leetcode. 11 --- container with the most water

Why do you perform performance tests before the software goes online? How to find a software performance testing organization
![组合总数[标准回溯 + 回溯技巧--降低栈深度]](/img/88/3a07589bf8edab618139b1bf1680e8.png)
组合总数[标准回溯 + 回溯技巧--降低栈深度]

Pycharm configuring remote connection server development environment

Reasons for the failure of digital transformation and the way to success

RapidEye快鸟、SPOT卫星遥感影像数据

Système de bibliothèque libre - service - cas de conception complète de l'interface tkinter et du formulaire openpyxl
随机推荐
下一个排列[发挥主观能动性发现规律]
Several methods of changing 91 Oracle common table into partitioned table
Mysql database DML operation exercise
What if the SQL execution plan of the production system suddenly becomes worse?
新捷途X70S上市8.79万起,空间安全越级,不愧是网红国民大7座SUV
Remote access and control - SSH Remote Management and TCP wrappers access control
[path planning] week 1: Path Planning open source code summary (ROS) version
立體渲染
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design
[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields
v-if和v-for哪个优先级更高?
SPA项目开发之CRUD+表单验证
腾讯云上传文件出现的问题:in a frame because it set ‘X-Frame-Options‘ to ‘deny‘.
pycharm 配置远程连接服务器开发环境
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
Seriously, the hang up of the kotlin collaboration process is not so mysterious (principle)
How much do you know about the cause of amplifier distortion?
Greedy interval problem (4)
R language builds a binary classification model based on H2O package: using H2O GLM constructs regularized logistic regression model and uses H2O AUC value of AUC calculation model
Shell (34): time