May Hacker 2022-01-26 18:30:42 阅读数:192
Don't take the initiative to delete expired key, When you need this key When , To check whether it has expired , Delete after expiration key
Delimit a certain time frame , That is, polling , Judge key Has it expired , Delete after expiration key
It should be noted that either regular deletion or lazy deletion is not a completely accurate deletion , There will still be key Scenes that have not been deleted , So we need Memory retirement strategy To supplement .
There are several memory elimination strategies :
noeviction: When memory usage exceeds configuration, an error is returned , It doesn't evict any keys
allkeys-lru: When you add a key , If it goes too far , First, through LRU The algorithm expels the longest unused key
volatile-lru: When you add a key, if it's too limited , First, remove the key from the key set with the expiration time Not used for the longest time Key
allkeys-random: When you add a key, if it's too limited , From all key Random delete
volatile-random: When you add a key, if it's too limited , Randomly expel... From the set of expired keys
volatile-ttl: Evict keys that are about to expire from keys that are configured with expiration time
volatile-lfu: From all keys configured with expiration time Use the least frequent key
allkeys-lfu: Eject the least frequently used key from all keys
There are three main types :LRU Most recently unused ( It doesn't have much to do with the number of times , Concerned about recent usage , Ready to use or not )、 Random delete 、LFU Not often these days ( Realize... According to the number of times of use )
copyright:author[May Hacker],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261830407225.html