Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memcached LRU and expiry

Tags:

memcached

If an item in memcached is set to never expire, is it exempt from LRU eviction?

The docs that I've seen don't paint a clear picture as to which takes precedence. In my mind, it would be ideal (perhaps very complicated internally) to have LRU only apply to items that had an expiry > 0.

like image 944
Mark Avatar asked Feb 10 '11 20:02

Mark


2 Answers

No, it is not exempt. Memcached is a cache, not persistent storage. Any item within it, or the entire cache itself may disappear at any moment (but it's not likely unless it's full, or there's a major problem).

Under heavy memory pressure, the LRU algorithm will remove whatever it feels necessary.

What is memcached's cache?

The cache structure is an LRU (Least Recently Used), plus expiration timeouts. When you store items into memcached, you may state how long it should be valid in the cache. Which is forever, or some time in the future. If the server is out of memory, expired slabs are replaced first, then the oldest unused slabs go next.

If the system has no areas of expired data, it will throw away the least recently used block (slab) of memory.

like image 68
Alister Bulman Avatar answered Sep 29 '22 02:09

Alister Bulman


The doc said that when expirezero_does_not_evict is set to 'true', items with 0 exptime cannot evict.

like image 24
andy Avatar answered Sep 29 '22 00:09

andy