当前位置:网站首页>Redis cache update strategy actively
Redis cache update strategy actively
2022-08-09 09:58:00 【ruochen】
- Cache Aside Pattern: By the caller of the cache, the cache is updated at the same time as the database is updated
- Read/Write Through Pattern: The cache and the database are integrated into a service, and the service maintains the consistency.The caller calls the service without having to care about cache coherency
- Write Behind Caching Pattern: The caller only operates the cache, and other threads asynchronously persist the cached data to the database to ensure eventual consistency
- Comparatively speaking, the
Cache Aside Pattern
is more reliable - There are several issues to consider when manipulating caches and databases - delete cache or update cache?- Update the cache: Update the cache every time the database is updated, and there are many invalid writes - Delete the cache: Invalidate the cache when updating the database, and update the cache when querying (Better) - How to ensure the cache and databaseThe operation succeeds or fails at the same time?(Atomicity) - Monolithic system: transaction control - Distributed system: Using distributed transaction schemes such as TCC - Operation cache or database first?(Thread safety) - Delete the cache first, then operate the database - First operate the database, then delete the cache - Since redis is much faster than MySQL, solution 2 is preferred
insert image description here - The best solution for cache update strategy- Low consistency requirement: Use Redis's own memory elimination mechanism- High consistency requirement: Active update, and take timeout culling as the bottom line - Read operation: - Return directly if the cache hits- If the cache misses, query the database, write to the cache, and set the timeout period. - Write operation: - write to the database first, and then delete the cache - to ensure the atomicity of database and cache operations
边栏推荐
猜你喜欢
【个人学习总结】CRC校验原理及实现
超详细的MySQL基本操作
Ontology development diary 04 - to try to understand some aspects of protege
Ontology Development Diary 05-Strive to Understand SWRL (Part 2)
快速解决MySQL插入中文数据时报错或乱码问题
接口设计
Arrays类、冒泡排序、选择排序、插入排序、稀疏数组!
免费下载天地图全国基础地理信息矢量数据的一种方法
[ASM] Bytecode operation MethodVisitor case combat generation object
【八大排序①】插入排序(直接插入排序、希尔排序)
随机推荐
时间复杂度和空间复杂度
LeetCode148:排序链表 归并排序,思路清晰,C语言练习看过来!
字符串函数和内存函数
Dream Notes 0809
8.Properties property collection
通过程序发送 Gmail 邮件
函数二
EndNoteX9 OR X 20 指南
Sweet alert
1. The concept of flow
【ASM】字节码操作 MethodVisitor 案例实战 生成对象
多线程案例——阻塞式队列
多线程案例——定时器
动态内存管理
Ontology Development Diary 03-Understanding Code
2.线程创建
Cisco common basic configuration of common commands
集合与函数
【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
【机器学习】数据科学基础——机器学习基础实践(二)