Module org.omnifaces
Package org.omnifaces.util.cache
Class LruCache<K extends Serializable,V extends Serializable>
- java.lang.Object
-
- org.omnifaces.util.cache.LruCache<K,V>
-
- Type Parameters:
K
- The generic map key type.V
- The generic map value type.
- All Implemented Interfaces:
Serializable
,ConcurrentMap<K,V>
,Map<K,V>
public class LruCache<K extends Serializable,V extends Serializable> extends Object implements ConcurrentMap<K,V>, Serializable
Minimal implementation of thread safe LRU cache with support for eviction listener. Inspired by ConcurrentLinkedHashMap.- Since:
- 4.4
- Author:
- Bauke Scholtz
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LruCache(int maximumCapacity)
Construct LRU cache with given maximum capacity.LruCache(int maximumCapacity, FunctionalInterfaces.SerializableBiConsumer<K,V> evictionListener)
Construct LRU cache with given maximum capacity and eviction listener.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
V
get(Object key)
boolean
isEmpty()
Set<K>
keySet()
V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> map)
V
putIfAbsent(K key, V value)
V
remove(Object key)
boolean
remove(Object key, Object value)
V
replace(K key, V value)
boolean
replace(K key, V oldValue, V newValue)
int
size()
Collection<V>
values()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
-
-
-
Constructor Detail
-
LruCache
public LruCache(int maximumCapacity)
Construct LRU cache with given maximum capacity.- Parameters:
maximumCapacity
- The maximum capacity.- Throws:
IllegalArgumentException
- when maximum capacity is less than 2.
-
LruCache
public LruCache(int maximumCapacity, FunctionalInterfaces.SerializableBiConsumer<K,V> evictionListener)
Construct LRU cache with given maximum capacity and eviction listener.- Parameters:
maximumCapacity
- The maximum capacity.evictionListener
- The eviction listener.- Throws:
IllegalArgumentException
- when maximum capacity is less than 2.
-
-
Method Detail
-
get
public V get(Object key)
- Specified by:
get
in interfaceMap<K extends Serializable,V extends Serializable>
-
put
public V put(K key, V value)
- Specified by:
put
in interfaceMap<K extends Serializable,V extends Serializable>
-
putIfAbsent
public V putIfAbsent(K key, V value)
- Specified by:
putIfAbsent
in interfaceConcurrentMap<K extends Serializable,V extends Serializable>
- Specified by:
putIfAbsent
in interfaceMap<K extends Serializable,V extends Serializable>
-
putAll
public void putAll(Map<? extends K,? extends V> map)
- Specified by:
putAll
in interfaceMap<K extends Serializable,V extends Serializable>
-
remove
public V remove(Object key)
- Specified by:
remove
in interfaceMap<K extends Serializable,V extends Serializable>
-
remove
public boolean remove(Object key, Object value)
- Specified by:
remove
in interfaceConcurrentMap<K extends Serializable,V extends Serializable>
- Specified by:
remove
in interfaceMap<K extends Serializable,V extends Serializable>
-
replace
public V replace(K key, V value)
- Specified by:
replace
in interfaceConcurrentMap<K extends Serializable,V extends Serializable>
- Specified by:
replace
in interfaceMap<K extends Serializable,V extends Serializable>
-
replace
public boolean replace(K key, V oldValue, V newValue)
- Specified by:
replace
in interfaceConcurrentMap<K extends Serializable,V extends Serializable>
- Specified by:
replace
in interfaceMap<K extends Serializable,V extends Serializable>
-
clear
public void clear()
- Specified by:
clear
in interfaceMap<K extends Serializable,V extends Serializable>
-
size
public int size()
- Specified by:
size
in interfaceMap<K extends Serializable,V extends Serializable>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceMap<K extends Serializable,V extends Serializable>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K extends Serializable,V extends Serializable>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K extends Serializable,V extends Serializable>
-
keySet
public Set<K> keySet()
- Specified by:
keySet
in interfaceMap<K extends Serializable,V extends Serializable>
-
values
public Collection<V> values()
- Specified by:
values
in interfaceMap<K extends Serializable,V extends Serializable>
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
- Specified by:
entrySet
in interfaceMap<K extends Serializable,V extends Serializable>
-
-