memcached 中的惰性过期机制是如何运作的?
(首先,我的英语不是很好,请)
我们知道,memcached提供延迟过期,并“替换”其slab中的LRU数据,但是我不太清楚它是如何做到这一点的。例如,如果一个slab已经满了,但是这个slab中的一些数据已经过期,那么当向该slab添加数据时会发生什么?
- memcached 是找到一些过期的数据并用添加的数据替换它们,还是
- 替换 LRU 数据,还是
- 做其他事情?
据我所知,延迟过期是指memcached不会主动从每个slab中删除过期数据,而是仅在引用过期条目的key时删除过期条目。这是一种资源浪费,不是吗?
(First of all, my English is not very good, please)
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?
- Does memcached find some expired data and replace them with the added data, or
- does it replace the LRU data, or
- does it do something else?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当请求某个项目时(获取请求)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.
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.