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 LRUCachewith a fixed capacity. If the cache reaches the capacity, it discards the least recently used entry first.This implementation is backed by a
ConcurrentHashMapfor storing the cached values and aConcurrentLinkedQueuefor 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 voidclear()Removes all of the elements from this cache.Vget(K key)Gets an entry from the cache.booleanisEmpty()Returnstrueif this cache contains no key-value mappings.java.util.Set<K>keySet()Returns aSetview of the keys contained in this cache.voidremove(K key)Removes the specified element from this cache if it is present.intsize()Returns the number of elements in this cache.
-
-
-
Method Detail
-
remove
public void remove(K key)
Description copied from interface:CacheRemoves the specified element from this cache if it is present.
-
clear
public void clear()
Description copied from interface:CacheRemoves all of the elements from this cache.
-
keySet
public java.util.Set<K> keySet()
Description copied from interface:CacheReturns aSetview of the keys contained in this cache.
-
size
public int size()
Description copied from interface:CacheReturns the number of elements in this cache.
-
-