Package com.alibaba.druid.util
Class ConcurrentLruCache<K,V>
- java.lang.Object
-
- com.alibaba.druid.util.ConcurrentLruCache<K,V>
-
public final class ConcurrentLruCache<K,V> extends Object
Simple LRU (Least Recently Used) cache, bounded by a specified cache capacity. This is a simplified, opinionated implementation of an LRU cache It is inspired from ConcurrentLruCache.
-
-
Constructor Summary
Constructors Constructor Description ConcurrentLruCache(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()VcomputeIfAbsent(K key, Function<K,V> generator)booleancontains(K key)Determine whether the given key is present in this cache.voidforEach(BiConsumer<K,V> action)Vget(K key)Set<K>keys()booleanremove(K key)Immediately remove the given key and any associated value.intsize()
-
-
-
Method Detail
-
forEach
public void forEach(BiConsumer<K,V> action)
-
size
public int size()
-
clear
public void clear()
-
contains
public boolean contains(K key)
Determine whether the given key is present in this cache.- Parameters:
key- the key to check for- Returns:
trueif the key is present,falseif there was no matching key
-
remove
public boolean remove(K key)
Immediately remove the given key and any associated value.- Parameters:
key- the key to evict the entry for- Returns:
trueif the key was present before,falseif there was no matching key
-
-