Package com.aspectran.core.util.cache
Class ConcurrentLruCache<K,V>
- java.lang.Object
-
- com.aspectran.core.util.cache.ConcurrentLruCache<K,V>
-
- Type Parameters:
K
- the type of the key used for cachingV
- the type of the cached values
- All Implemented Interfaces:
Cache<K,V>
public class ConcurrentLruCache<K,V> extends java.lang.Object implements Cache<K,V>
A thread-safe LRUCache
with a fixed capacity. If the cache reaches the capacity, it discards the least recently used entry first.This implementation is backed by a
ConcurrentHashMap
for storing the cached values and aConcurrentLinkedQueue
for ordering the keys and choosing the least recently used key when the cache is at full capacity.- Since:
- 6.6.7
-
-
Constructor Summary
Constructors Constructor Description ConcurrentLruCache(int capacity, java.util.function.Function<K,V> generator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all of the elements from this cache.V
get(K key)
Gets an entry from the cache.boolean
isEmpty()
Returnstrue
if this cache contains no key-value mappings.java.util.Set<K>
keySet()
Returns aSet
view of the keys contained in this cache.void
remove(K key)
Removes the specified element from this cache if it is present.int
size()
Returns the number of elements in this cache.
-
-
-
Method Detail
-
remove
public void remove(K key)
Description copied from interface:Cache
Removes the specified element from this cache if it is present.
-
clear
public void clear()
Description copied from interface:Cache
Removes all of the elements from this cache.
-
keySet
public java.util.Set<K> keySet()
Description copied from interface:Cache
Returns aSet
view of the keys contained in this cache.
-
size
public int size()
Description copied from interface:Cache
Returns the number of elements in this cache.
-
-