本文介绍了当密钥具有不同的时间范围并且缓存已满时,memcached过期行为是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道redis会自行使密钥过期,从而释放内存并且想知道memcached是否会表现出相同的行为.

I know that redis will expire the keys on its own, freeing the memoryand was wondering if memcached would behave the same.

假设我有一种非常很少过期的缓存键(我们称它们为A),另一种则每5分钟过期一次,使用Ruby on Rails的expires_in: 5.minutes(我们称它们为B)

Let's say I have a kind of cache keys that are expired very rarely(we'll call them A), and another kind that expires every 5 minutes,using Ruby on Rails' expires_in: 5.minutes (we'll call them B)

如果B键过多,memcached会丢弃A键吗?

Will memcached drop the A keys if there are too many B keys ?

例如,如果我可以在自己的商店中存储5个值,则情况可能是:

For instance if I can store 5 values in my store, a scenario could be:

  • 存储A1(还剩4个值)
  • 存储B1(还剩3个值)
  • 存储B2(还剩2个值)
  • 存储B3(还剩1个值)
  • 存储B4(剩余0个值)

此时B1,B2和B3已过期(因为它们的生命周期如此简短).

At this point B1, B2 and B3 are expired (because their lifecycle is soshort).

如果我将另一个元素存储在缓存中怎么办?它会掉A1吗因为它是最古老的,或者它会知道B键寿命很短并且首先使用它们在内存中的位置吗?

What happens if I store another element in the cache ? Will it drop A1since it's the oldest, or will it know that B keys are short lived anduse their spot in the memory first ?

推荐答案

Memcached使用LRU(最近最少使用)机制来确定当要存​​储的对象数量多于可用空间时,哪些现有对象将到期.您可以进一步参考以下链接以了解其密钥到期机制: http://docs.oracle.com /cd/E17952_01/refman-5.6-en/ha-memcached-using-expiry.html

Memcached uses LRU (Least recently used) mechanism to determine which existing objects to expire when there are more number of objects to be stored than the space available. You can further refer to the following link to understand its mechanism for key expiry :http://docs.oracle.com/cd/E17952_01/refman-5.6-en/ha-memcached-using-expiry.html

这篇关于当密钥具有不同的时间范围并且缓存已满时,memcached过期行为是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:57