当前位置:网站首页>Things about caching in software design
Things about caching in software design
2022-07-17 23:50:00 【JavaMonsterr】

Cache is the simplest and most complex concept , With it, you can make your application fly , I won't use it , Even the highest configuration , Your application is also difficult to achieve the best results .
What is caching
Cache is the direct access of data by hardware or software , Not from the original source ( database , Calculation, etc ) Access data , It will speed up the reading of data .

Memory caching is a caching technology we often use , By saving commonly used data into memory , We can avoid reading data from the database , This will greatly improve the loading speed of the application , Enhance user experience .
When to use caching
- When we need to request external resources , For example, the third party api, We want to cache the result of the request
- When the requested data changes , We can cache the returned results
- When an application needs to request the same resource frequently
- When applications need to run some complex computers
- When applying queries takes time
Cache benefits
- Improve application performance
- Reduce database overhead
- Increase concurrency
The type of cache
- Application cache
- Database cache
- DNS cache
- Client cache
- CDN cache
- API Gateway cache
Distributed cache
Distributed cache is managed and controlled by a server , There are multiple client nodes storing data , It can further improve the data reading rate . So when we want to read some data , Which node should I choose ? If you search node by node , That's too inefficient . Therefore, it is necessary to determine the storage and reading nodes of data according to the consistent hash algorithm . With data D, Total number of nodes N Based on , The data is calculated by the consistent hash algorithm D Corresponding hash value ( Equivalent to the house number ), According to the hash value, you can find the corresponding node . The advantage of consistent hash algorithm is that the number of nodes changes ( Reduce or increase ) There is no need to recalculate the hash value , Ensure that data can be stored or read correctly 、 Quickly find the corresponding node .

Distributed cache can read data with high performance 、 It can dynamically expand cache nodes 、 It can automatically find and switch fault nodes 、 Can automatically balance data partition , And it can provide users with graphical management interface , It's easy to deploy and maintain .
Cache policy
(1) Cache-Aside
Read the cache first , If the cache fails , Then read the database to get data , Then set the data into the cache .

(2) Read Through
Applications only fetch data from the cache , If you don't get , Then the cache will get data from the database , Then set the cache , Finally, the application continues to read data from the cache .

(3) Write Through
When the application saves data , They are stored in the cache first , The cache will save the data to the database , Applications do not deal directly with databases , Just save the data to the cache .

(44) Write Back or Write Behind
The application writes data to the cache , Then it will send a confirmation back to the application , Then the cache is written to the database .

(5) Write Around
Application data is written directly to the database , So as to read the data and get it from the cache .

summary
A great man once said , All the computer problems we can't solve at present , Can be solved by adding an intermediate layer , The cache is an intermediate layer , With this middle layer , Our application performance has been greatly improved , But caching is not everything , It also has its drawbacks , Only use it reasonably , We can give full play to its maximum value .
边栏推荐
- 【C语言进阶】----常见的字符串函数
- The security optimization settings after the installation of Zhimeng CMS effectively protect Trojans
- 拼多多店铺所有商品API接口(整店商品列表查询接口)
- 统计年龄分布情况(5岁的间隔统计),绘制出年龄分布图。
- Shadow plug-in framework design -- replugin principle (Advanced journey of Architects)
- Gao Fushui in unit testing, pytest framework (III) use case marking and test execution
- 小工具(读取Excel数据并存入数据库表)
- Today, I went to oppo for an interview and got numb...
- OSPF experiment in mGRE environment
- Detailed explanation of synchnorized principle
猜你喜欢

hyper子查询优雅实现join查询

Letter combination of leecode17 phone number

. Net full scene development has finally arrived

Smart breeding scheme based on Lora gateway

PLC通过伯努利方程近似计算水箱流量(FC)

微信公众号开发-自定义菜单

The problem of idea configuring NPM to jump to 0.0.0.0 after startup is solved
![[Huawei online battle] download and run Huawei's official unity example code, prompting authentication failure and returning error code 100114](/img/32/7d796399ac996fd7da5609f0252dfb.png)
[Huawei online battle] download and run Huawei's official unity example code, prompting authentication failure and returning error code 100114

Sword finger offer 06 Print linked list from end to end

Go language pointer
随机推荐
用IP的SSL证书申请
内核的结构和设计
leecode17电话号码的字母组合
MySQL 读写分离配置实践
kali系统入门-Hping3的使用
Nvisual API interface instructions
Serein [lazy artifact] a graphical tool that collects URLs in batches and detects the collected URLs in batches. It solves the problem of fishing project
API interface for all products in pinduoduo store (whole store product list query interface)
接口测试——流程测试支持批量参数导入,测试效率直接拉满!
微信公众号-服务器配置(token验证)
API interface of all products in JD store (JD whole store product query API interface)
The most powerful cluster monitoring system, it always ranks first!
JMeter regular expression gets login token
Pytest+request+allure+excel interface automation from 0 to 1 [four allure test reports]
LOCUST性能测试1(认识)
Suning commodity details API interface (commodity details page data interface)
几行汇编几行C实现一个最简单的内核
Wechat applet - Advanced chapter package JSON Version Description and detailed explanation of various version symbols (I)
pytest+request+allure+excel接口自动化搭建 从0到1【二 读取Excel Case信息】
【C语言进阶】----常见的字符串函数