Package org.camunda.commons.utils.cache
Class ConcurrentLruCache<K,V>
java.lang.Object
org.camunda.commons.utils.cache.ConcurrentLruCache<K,V>
- Type Parameters:
K
- the type of keysV
- the type of mapped values
- All Implemented Interfaces:
Cache<K,
V>
A thread-safe LRU org.camunda.commons.utils.cache.Cache with a fixed capacity. If the cache reaches
the capacity, it discards the least recently used entry first.
*Note*: The consistency of the keys queue with the keys in the cache is not ensured! This means, the keys queue can contain duplicates of the same key and not all the keys of the queue are necessarily in the cache. However, all the keys of the cache are at least once contained in the keys queue.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the contents of the cache.Gets an entry from the cache.boolean
isEmpty()
Returnstrue
if this cache contains no key-value mappings.keySet()
Returns a Set view of the keys contained in this cache.void
Associates the specified value with the specified key in the cache.void
Removes an entry from the cache.protected void
Removes all instances of the given key within the keys queue.int
size()
-
Constructor Details
-
ConcurrentLruCache
public ConcurrentLruCache(int capacity) Creates the cache with a fixed capacity.- Parameters:
capacity
- max number of cache entries- Throws:
IllegalArgumentException
- if capacity is negative
-
-
Method Details
-
get
Description copied from interface:Cache
Gets an entry from the cache. -
put
Description copied from interface:Cache
Associates the specified value with the specified key in the cache. -
remove
Description copied from interface:Cache
Removes an entry from the cache. -
clear
public void clear()Description copied from interface:Cache
Clears the contents of the cache. -
isEmpty
public boolean isEmpty()Description copied from interface:Cache
Returnstrue
if this cache contains no key-value mappings. -
keySet
Description copied from interface:Cache
Returns a Set view of the keys contained in this cache. -
size
public int size() -
removeAll
Removes all instances of the given key within the keys queue.
-