cache and database
This article referenced from http://coolshell.cn/articles/17416.html
We all know that high concurrency, high I/O is a big challenge to database. So we normally add a cache system in front of database. The cache system normally store data inside the RAM so it has better performance.
But there is one big problem for this kind of architecture. The cache and database are two independent storage system. So data manipulation can not be atom between the two system. In other words, there might be data inconsistent.
To address the inconsistent problem, there are several strategies for cache and db communication.
Cache Aside Pattern
When reading data, application first read the cache. If hit, then get back with data. If miss, then get data from database, store the data in cache so that later query can get data from cache directly.
When updating data, application first update the database, then disable the corresponding item in cache.
This strategy may cause dirty data. For example:
time point 1: process a read entry e1 from db
time point 2: process b update e1 in db to E1 and process b disable the corresponding cache entry e1 in cache
time point 3: process a put entry e1 in cache
Now the e1 is the dirty data because the real data should be E1 now.
But this can rarely happen. Because read operation normally faster than write.
Read/Write Through Pattern
In read through. The application does not know there is a cache or db. To application, there is only one storage layer. In read through, when read from cache fail(the cache entry timeout or swap out because of LRU), the cache will responsible for retrieve data from db and store in cache.
In write through. The application will try to update the data in cache first. If no find the data in cache then update DB. If find the data in cache then update the data in cache and cache system will update DB.
Write Behind Caching Pattern
When update, the application only update cache. The cache will update database in batch. This is an asynchronous operation. The cache will be write back to DB in several circumstance like not enough space in cache. So this is also called lazy write.
This strategy may cause data loss.
cache and database的更多相关文章
- Enterprise Library深入解析与灵活应用(2): 通过SqlDependency实现Cache和Database的同步
对于一个真正的企业级的应用来说,Caching肯定是一个不得不考虑的因素,合理.有效地利用Caching对于增强应用的Performance(减少对基于Persistent storage的IO操作) ...
- 缓存方案 通过SqlDependency实现Cache和Database的同步
对于一个真正的企业级的应用来说,Caching肯定是一个不得不考虑的因素,合理.有效地利用Caching对于增强应用的Performance(减少对基于Persistent storage的IO操作) ...
- 【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之集群概念介绍(一)
集群概念介绍(一)) 白宁超 2015年7月16日 概述:写下本文档的初衷和动力,来源于上篇的<oracle基本操作手册>.oracle基本操作手册是作者研一假期对oracle基础知识学习 ...
- 序列sequence中的cache问题
Oracle中序列Sequence的创建语法如下: CREATE SEQUENCE [ schema. ] sequence [ { INCREMENT BY | START WITH } integ ...
- Library Cache: Lock, Pin and Load Lock
What is "Library cache lock" ? This event controls the concurrency between clients of the ...
- Up-to-date cache with EclipseLink and Oracle
Up-to-date cache with EclipseLink and Oracle One of the most useful feature provided by ORM librarie ...
- 基于EFCore的数据Cache实现
.NetCore 内置缓存加入到EFCore操作中,数据更新或者查询时自动更新缓存.github地址 2019-04-27 初步完成逻辑代码编写,尚未经过测试,诸多细节有待完善. 2019-04-28 ...
- 【转】【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之集群概念介绍(一)
原文地址:http://www.cnblogs.com/baiboy/p/orc1.html 阅读目录 目录 集群概念介绍 什么是集群 为什么搭建数据库集群 数据库集群的分类 可扩展的分布式数据库架构 ...
- Oracle 12.1.0.2 New Feature翻译学习【In-Memory column store内存列存储】【原创】
翻译没有追求信达雅,不是为了学英语翻译,是为了快速了解新特性,如有语义理解错误可以指正.欢迎加微信12735770或QQ12735770探讨oracle技术问题:) In-Memory Column ...
随机推荐
- jQuery的属性与样式之样式操作.css()
.css() 方法:获取元素样式属性的计算值或者设置元素的CSS属性 获取: .css( propertyName ) :获取匹配元素集合中的第一个元素的样式属性的计算值 .css( property ...
- [Windows Server 2012] 阿里云镜像购买和使用方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将演示:阿里云镜像购买 ...
- Android嵌入式安卓触摸屏|4418开发板平台
核心板参数 尺寸:50mm*60mm 高度:核心板连接器为1.5mm 4418 CPU:ARM Cortex-A9 四核 S5P4418处理器 1.4GHz 6818 CPU:ARM Cortex-A ...
- vim 将文件所有行合并到一行
vim 将文件所有行合并到一行 在 Normal Mode下执行: ggvGJ gg 用于跳到行首 v 转换成 visual 模式 G 跳到最后一行 J 合并行
- windows sdk编程隐藏窗体标题栏
#include <windows.h> /*消息处理函数声明*/ HRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM ...
- 取消input聚焦时的边框,去除ios点击时,自动添加的底色效果
/*去除ios点击时,自动添加的底色效果*/ -webkit-tap-highlight-color: rgba(, , , ); /*去除焦点框*/ outline:none;
- 07CSS表格
CSS表格 表格边框 如需在 CSS 中设置表格边框,请使用 border 属性. table, th, td { border: 1px solid blue; } 折叠边框 border-coll ...
- left_v2.js
$(document).ready(function(){ $(".mc_left a").each(function(){ var href = $(this).attr(&qu ...
- LG-P1311选择客栈
题目 暴力十分好想但你写不出来qwq 正解十分好写但你想不出来qaq 我们先读题,发现k其实没什么用 同时暴力枚举两个客栈的话会超时,所以只能同时枚举一个.我们枚举第二个客栈,然后用第二个客栈反推出前 ...
- mybatis传多个参数(不使用@param注解情况下),3.4.2版本之后出现#{0}-#{n}参数绑定异常
解决方案: 在mybatis配置文件中声明setting属性的useActualParamName 参数值为false ** 这种方法解决mybatis3.4.2之后的版本产生该问题的解决方法**