How does the lazy expiration mechanism in memcached operate?
Asked Answered
C

1

3

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

Cuspidor answered 13/5, 2011 at 3:7 Comment(0)
F
5

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.

Frydman answered 13/5, 2011 at 3:50 Comment(2)
if the slab is full with some expired data in it .but these expired data has not requested, so, it will use LRU mechinism to replace the least used item in the cache . am i right?Cuspidor
here is updated docs on this - github.com/memcached/memcached/wiki/…Verdun

© 2022 - 2024 — McMap. All rights reserved.