使用memcached和MySQL等rdbms时的缓存一致性 [英] Cache consistency when using memcached and a rdbms like MySQL

查看:119
本文介绍了使用memcached和MySQL等rdbms时的缓存一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本学期我上了数据库课,我们正在研究如何维护RDBMS与诸如memcached之类的缓存服务器之间的缓存一致性.在存在竞争条件时会出现一致性问题.例如:

I have taken a database class this semester and we are studying about maintaining cache consistency between the RDBMS and a cache server such as memcached. The consistency issues arise when there are race conditions. For example:

  1. 假设我从缓存中执行了get(key),并且有一个缓存未命中.因为遇到高速缓存未命中,所以我从数据库中获取数据,然后对高速缓存执行put(key,value).
  2. 但是,可能会发生争用情况,其他用户可能会删除我从数据库中提取的数据.在我对缓存执行put之前,可能会发生这种删除.
  1. Suppose I do a get(key) from the cache and there is a cache miss. Because I get a cache miss, I fetch the data from the database, and then do a put(key,value) into the cache.
  2. But, a race condition might happen, where some other user might delete the data I fetched from the database. This delete might happen before I do a put into the cache.

因此,理想地,不应将put进入高速缓存,因为数据库中数据的存在时间越来越长.

Thus, ideally the put into the cache should not happen, since the data is longer present in the database.

如果缓存条目具有TTL,则缓存中的条目可能会过期.但是,仍然存在一个窗口,其中缓存中的数据与数据库不一致.

If the cache entry has a TTL, the entry in the cache might expire. But still, there is a window where the data in the cache is inconsistent with the database.

我一直在寻找有关此类问题的文章/研究论文.但是,我找不到任何有用的资源.

I have been searching for articles/research papers which speak about this kind of issues. But, I could not find any useful resources.

推荐答案

本文为您提供了有关Facebook如何(尝试)保持缓存一致性的有趣注释:

This article gives you an interesting note on how Facebook (tries to) maintain cache consistency : http://www.25hoursaday.com/weblog/2008/08/21/HowFacebookKeepsMemcachedConsistentAcrossGeoDistributedDataCenters.aspx

这是本文的要点.

  1. 我将名字从"Jason"更新为"Monkey"
  2. 我们在加利福尼亚的master数据库中写入"Monkey",然后从加利福尼亚的内存缓存中删除我的名字,但从弗吉尼亚州删除
  3. 有人去了我在弗吉尼亚州的个人资料
  4. 我们在内存缓存中找到了我的名字,并返回"Jason"
  5. 复制赶上了,我们用我的名字"Monkey"更新了从数据库. 我们还从弗吉尼亚州内存缓存中删除了我的名字,因为该缓存对象出现在复制流中
  6. 其他人进入了我在弗吉尼亚州的个人资料
  7. 我们在内存缓存中找不到我的名字,所以我们从奴隶那里读取并获得猴子"
  1. I update my first name from "Jason" to "Monkey"
  2. We write "Monkey" in to the master database in California and delete my first name from memcache in California but not Virginia
  3. Someone goes to my profile in Virginia
  4. We find my first name in memcache and return "Jason"
  5. Replication catches up and we update the slave database with my first name as "Monkey." We also delete my first name from Virginia memcache because that cache object showed up in the replication stream
  6. Someone else goes to my profile in Virginia
  7. We don't find my first name in memcache so we read from the slave and get "Monkey"

这篇关于使用memcached和MySQL等rdbms时的缓存一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆