Redis › Expiration & Eviction
What is the difference between the LRU and LFU eviction algorithms, and when would you choose one over the other?
IntermediateAnswer
LRU, meaning least recently used, evicts the key that has not been accessed for the longest time, while LFU, meaning least frequently used, evicts the key that has been accessed the fewest number of times overall, with LFU generally being a better choice when some keys are accessed very frequently over a long period even if there are occasional gaps between accesses.
CONFIG SET maxmemory-policy allkeys-lfuReal-world example A recommendation engine that repeatedly accesses certain popular product keys throughout the day, but with occasional gaps, chooses LFU eviction to avoid accidentally evicting those consistently popular keys just because they were not accessed in the last few minutes.