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的更多相关文章

  1. Enterprise Library深入解析与灵活应用(2): 通过SqlDependency实现Cache和Database的同步

    对于一个真正的企业级的应用来说,Caching肯定是一个不得不考虑的因素,合理.有效地利用Caching对于增强应用的Performance(减少对基于Persistent storage的IO操作) ...

  2. 缓存方案 通过SqlDependency实现Cache和Database的同步

    对于一个真正的企业级的应用来说,Caching肯定是一个不得不考虑的因素,合理.有效地利用Caching对于增强应用的Performance(减少对基于Persistent storage的IO操作) ...

  3. 【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之集群概念介绍(一)

    集群概念介绍(一)) 白宁超 2015年7月16日 概述:写下本文档的初衷和动力,来源于上篇的<oracle基本操作手册>.oracle基本操作手册是作者研一假期对oracle基础知识学习 ...

  4. 序列sequence中的cache问题

    Oracle中序列Sequence的创建语法如下: CREATE SEQUENCE [ schema. ] sequence [ { INCREMENT BY | START WITH } integ ...

  5. Library Cache: Lock, Pin and Load Lock

    What is "Library cache lock" ? This event controls the concurrency between clients of the ...

  6. 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 ...

  7. 基于EFCore的数据Cache实现

    .NetCore 内置缓存加入到EFCore操作中,数据更新或者查询时自动更新缓存.github地址 2019-04-27 初步完成逻辑代码编写,尚未经过测试,诸多细节有待完善. 2019-04-28 ...

  8. 【转】【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之集群概念介绍(一)

    原文地址:http://www.cnblogs.com/baiboy/p/orc1.html 阅读目录 目录 集群概念介绍 什么是集群 为什么搭建数据库集群 数据库集群的分类 可扩展的分布式数据库架构 ...

  9. Oracle 12.1.0.2 New Feature翻译学习【In-Memory column store内存列存储】【原创】

    翻译没有追求信达雅,不是为了学英语翻译,是为了快速了解新特性,如有语义理解错误可以指正.欢迎加微信12735770或QQ12735770探讨oracle技术问题:) In-Memory Column ...

随机推荐

  1. mysql 的 case when then 用法 和null 的判断

    表:一个表 aa 有两个字段 id 和 sex ,第1条记录的sex 为空串  ('')  第二条记录的sex 为空  (null) 1. 用法: 第一种: select (case 字段名  whe ...

  2. tomcat 启动失败 和闪退 和 启动成功却没有页面显示

    1.解压版tomcat 将tomcat解压至英文目录下, 在系统环境变量里面配置 JAVA_HOME 和CATALINA_HOME (就是tomcat的安装目录) 在path中配置 %CATALINA ...

  3. Java入门第39课——猜字母游戏之实现字母生成方法

    问题        实现猜字母游戏中的字母生成方法,即,随机生成5个不同的字母作为猜测的结果. 方案        实现generate方法,首先声明一个字符类型的数组,用于存储26个大写字母,然后声 ...

  4. 类unix系统 递归删除指定文件

    递归删除当前目录下所有以 ._开头的文件 find . -name "._*" | xargs rm -f 或者: find . -name "._*" -ex ...

  5. lua 之 三木运算符

    在c语言中我三目运算符这么写: a?b:c 例如: max = a>b?a:b; 在lua中我们这么写 max = a>b and a or b 运行如下:

  6. Vue打包之后部署到 express 服务器上

    Part.1 安装 express npm install express body-parer --save Part.2 在项目根目录下创建 app.js 文件作为启动 express 服务器代码 ...

  7. ES5和ES6新的操作数组的方法(常用)

    // 普通的for循环// var arr = ['张飞', '赵云', '马超', '刘备']// for (var i = 0; i < arr.length; i++) {// conso ...

  8. CentOS7-wget命令

    Wget主要用于下载文件,在安装软件时会经常用到,以下对wget做简单说明.转载自:https://www.cnblogs.com/lxz88/p/6278268.html 1.下载单个文件:wget ...

  9. P5304 [GXOI/GZOI2019]旅行者(最短路/乱搞)

    luogu bzoj Orz自己想出神仙正解的sxy 描述略 直接把所有起点推进去跑dijkstra... 并且染色,就是记录到这个点的最短路是由哪个起点引导出来的 然后再把所有边反指跑一次... 之 ...

  10. 笔试算法题(17):奇偶数分置数组前后段 & 反序访问链表

    出题:输入一个数组,要求通过交换操作将奇数索引的元素调整到数组前半部分,偶数索引的元素调整到数组后半部分: 分析: 当然如果没有额外要求的话很容易实现,最好使用In-Place的实现策略:考虑插入排序 ...