Comments for post Redis as an LRU cache

Newbie writes: I'd like to set TTL on keys so that they stay in the cache no longer than X amount of time. Then I'd like to set the policy to volitile-LRU. Am I correct in believing that even if a key has been very recently used when its TTL is up, it will be purged? Even if the cache is nowhere near maxbytes? This way, stale data always gets purged and otherwise older data gets purged if we run out of memory.
Kore writes: The allkeys-lru policy sounds like it could be quite handy in my deployment. I've been hoping for the ability to update expiry times to simulate LRU behaviour, but this is even better. Appreciate all your work Salvatore, keep it up!
antirez writes: @Brian: the whole point of using a "sample three" algorithm is to save memory. I think this is much more valuable than precision, especially since this randomized algorithms are rarely well understood. An example: sampling with just three objects will expire 666 objects out of a dataset of 999 with an error rate of only 14% compared to the *perfect* LRU algorithm. And in the 14% of the remaining there are hardly elements that are in the range of very used elements. So the memory gain will pay for the precision without doubts. Not sure why you use two thresholds, I think that using one is better as you fix the amount of memory Redis should use, and it will respect your willing deleting old data as you put more new data. Memcached-style.
Brian Bulkowski writes: Citrusleaf, the clustered key-value database, has a very similar expiration feature, but it has two thresholds. The first threshold is when to activate the 'eviction' feature, which starts removing the oldest volatile keys, and the second stops writes if the maximum amount of memory is reached. Having a mark-and-sweep style of eviction gives much more fidelity than "sample three", and having stop-writes gives protection in all use scenarios against run-away writes beyond the capacity of memory. Check out the wiki: http://citrusleaf.net/moin/server/moin.cgi
obs writes: I like the allkeys-lru option :)
antirez writes: @teleo: no, voletile-ttl is indeed the old behavior, but the new default is instead volatile-lru that is I guess what most people will want to start.
teleo writes: Hi Salvatore, Is the default eviction policy volatile-ttl?
home