Package com.aspectran.utils.cache
Class ConcurrentLruCache<K,V>
java.lang.Object
com.aspectran.utils.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>
A thread-safe LRU
Cache
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 a ConcurrentLinkedQueue
for ordering the keys
and choosing the least recently used key when the cache is at full capacity.
- Since:
- 6.6.7
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all of the elements from this cache.Gets an entry from the cache.boolean
isEmpty()
Returnstrue
if this cache contains no key-value mappings.keySet()
Returns aSet
view of the keys contained in this cache.void
Removes the specified element from this cache if it is present.int
size()
Returns the number of elements in this cache.
-
Constructor Details
-
ConcurrentLruCache
-
-
Method Details
-
get
Description copied from interface:Cache
Gets an entry from the cache. -
remove
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
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. -
isEmpty
public boolean isEmpty()Description copied from interface:Cache
Returnstrue
if this cache contains no key-value mappings.
-