I have a question on Redis cache's behavior. Kindly clarify -
Say, for a key "xyz" if the TTL is set to 15 minutes. And, if its eviction policy in server level is set to "allkeys-lru". Does expired items(cause of TTL) EXPIRE or WAIT until the memory is full?
Redis supports various eviction policies including Least Recently Used (LRU), Least Frequently Used (LFU), Random Eviction, and Shorter Time-to-Live (TTL) [20]. Among those policies, LRU replacement is the most commonly chosen policy in industry for both software and hardware caches.
By default, Amazon ElastiCache for Redis sets the volatile-lru eviction policy for your Redis cluster. When this policy is selected, the least recently used (LRU) keys that have an expiration (TTL) value set are evicted.
The reason Redis does not use a true LRU implementation is because it costs more memory. However, the approximation is virtually equivalent for an application using Redis.
LRU (or Least Recently Used) is a cache eviction strategy, wherein if the cache size has reached the maximum allocated capacity, the least recently accessed objects in the cache will be evicted.
The eviction policy only applies to what happens when you exceed the max memory. As long as you're within your memory limits, volatile keys will expire when they should be expired.
Once your memory is full, an LRU algorithm kicks in, evicting least recently used keys. In allkeys-lru
, it doesn't matter whether a key is expired or not and what is the TTL - the least used items will be evicted. In volatile-lru
only expiring keys will be evicted using this algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With