On 22. juli. 2009, at 22.36, dl4ner wrote:
Trond,
Well, it will allocate a new item unless it finds an expired item in
the tail of the item LRU. You may have expired items in the middle of
your LRU list, and you would still evict items from the cache if all
memory is allocated.
I just read this now. Do I understand correctly that if all items
would have the same livetime (e.g. 300 sec), the LRU chain should
contain an expired object every now and then.
But when we use different livetimes (e.g. 300 + 86400), it could come
to this case: the end of LRU is a long-living but still good item, so
all other (out-of-date) item after that in the change won't be
reused?
this would explain some here, as we use different cache times
from 300 over 3600 over 86400 to maximum (30days AFAIR).
The thing is that we use a linked list to store all of the items in.
Every time a user tries to use an item (get / set / incr etc), the
item will be moved to the beginning of the linked list. Whenever you
try to insert an item in the cache, the first thing we will do is to
look in the tail of the linked list to see if we have any expired
items (we will only look at 50 items). If we don't find any expired
items there, we will try to allocate memory. If the allocation fails,
we will return to the linked list and evict an object from the tail.
This means that if your list look somewhat like
expired, expired, expired, and then 50 not expired
you would evict one of the not expired items even if we have expired
items in the list, because we don't search that far in the item list.
Cheers,
Trond