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. js 复制文字、 复制链接到粘贴板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 查看DNS、IP、Mac等

    A.Win98:winipcfg  B.Win2000以上:Ipconfig/all  C.NSLOOKUP:如查看河北的DNS  C:\\>nslookup  Default Server: ...

  3. c++ 模板template

    1.函数模板的声明 声明形式 template<typename 数据类型参数标识符> <返回类型><函数名>(参数表) {     函数体 } 注: templa ...

  4. 【计算机网络】2.2 Web和HTTP

    第二章第二节 Web和HTTP 这一章中,我们需要讨论5种重要的应用:Web.文件传输.电子邮件.目录服务.P2P:这一节中,我们将讨论Web和它的应用层协议HTTP. Outline Web简介 H ...

  5. 微信小程序图片上传java后台(前后端代码)

    小程序代码 upload:function(e){ var that = this; wx.showActionSheet({ itemList: ['从相册选择','拍照'], itemColor: ...

  6. yum升级php版本

    查看当前 PHP 版本 1 php -v 查看当前 PHP 相关的安装包,删除之 1 2 3 4 5 yum list installed | grep php   yum remove php   ...

  7. 第3节 hive高级用法:15、hive的数据存储格式介绍

    hive当中的数据存储格式: 行式存储:textFile sequenceFile 都是行式存储 列式存储:orc parquet 可以使我们的数据压缩的更小,压缩的更快 数据查询的时候尽量不要用se ...

  8. vue-cli webpack 快速搭建项目

    一.安装vue npm install vue -g 二.用vue-cli快速搭建项目 //全局安装vue-cli npm install install -g vue-cli //创建一个基于web ...

  9. java IO流 内容整理

    在java中,对数据的输入和输出操作以流的方式进行.(注:对文件的操作用io.File类,但不能对文件中的内容进行操作) 一.IO流的分类: 按数据流的方向不同,可以分为输入流和输出流: 按处理数据的 ...

  10. 树莓派--bcm2835 library (2) 交叉编译BCM2835

    在上文中,按照guide, 在树莓派目标板上install bcm2835. 因为bcm2835是用户空间应用,所以可以在宿主机上交叉编译,生成binary后在树莓派执行 按照guide: Insta ...