What is memcached expiration behavior when keys have different time frames and the cache is full?

有些话、适合烂在心里 提交于 2019-12-23 17:18:45

问题


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


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)

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

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

  • Store A1 (4 values left)
  • Store B1 (3 values left)
  • Store B2 (2 values left)
  • Store B3 (1 values left)
  • Store B4 (0 values left)

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


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


回答1:


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



来源:https://stackoverflow.com/questions/22500824/what-is-memcached-expiration-behavior-when-keys-have-different-time-frames-and-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!