How does the lazy expiration mechanism in memcache

2019-01-26 20:46发布

(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?

  1. Does memcached find some expired data and replace them with the added data, or
  2. does it replace the LRU data, or
  3. 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?

标签: memcached lru
1条回答
仙女界的扛把子
2楼-- · 2019-01-26 21:19

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.

查看更多
登录 后发表回答