memcached中的惰性过期机制如何运作? [英] How does the lazy expiration mechanism in memcached operate?

查看:102
本文介绍了memcached中的惰性过期机制如何运作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(首先,请问我的英语不是很好)

(First of all, my English is not very good, please)

我们知道,memcached提供了延迟过期,并在其slab中替换"了LRU数据,但是我不太清楚它是如何做到的.例如,如果一个平板已满,但该平板中的某些数据已过期,那么将数据添加到该平板时会发生什么?

As we know, memcached provides lazy expiration, and "replaces" LRU data in its slabs, however I'm not very clear how it does this. For example, if a slab is full, but some data in this slab are expired, what will happen when data are added to the slab?

  1. memcached是否找到一些过期数据并将其替换为添加的数据,或者
  2. 是否替换LRU数据,或
  3. 它还会做其他事情吗?

据我所知,延迟过期是这样的,memcached不会主动从每个slab删除过期的数据,而是仅在引用过期条目的键时才删除过期条目.这是浪费资源,不是吗?

As far as I know, the lazy expiration is such that memcached is not actively removing expired data from each slab, but instead only removing expired entries when the key of the expired entry is referenced. This is a waste of resources, isn't it?

推荐答案

请求项目(获取请求)时,Memcached检查 退货前要检查商品是否仍然有效的到期时间 给客户.

When an item is requested (a get request) Memcached checks the expiration time to see if the item is still valid before returning it to the client.

类似地,当向缓存中添加新项目时,如果缓存已满, 它将在替换之前寻找过期物品以进行替换 缓存中使用最少的项目.

Similarly when adding a new item to the cache, if the cache is full, it will look at for expired items to replace before replacing the least used items in the cache.

因此,仅当有get请求时才清除过期的项目 已发送过期商品或过期商品已清除,因为 需要存储.

So expired items are only purged when a get request is sent for the expired item or the expired item is cleared because the storage is needed.

这篇关于memcached中的惰性过期机制如何运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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