Package org.apache.camel.support.cache
Class SimpleSoftCache<K,V>
java.lang.Object
org.apache.camel.support.cache.SimpleSoftCache<K,V>
- Type Parameters:
K
- type of the keyV
- type of the value
- All Implemented Interfaces:
Map<K,
V>
SimpleSoftCache
is a simple implementation of a cache where values are soft references which allows the
Garbage Collector to clear the referents in response of a memory demand to potentially prevent
OutOfMemoryError
. The entries where the referent is missing are removed lazily when they are accessed
directly or indirectly through the Map
API. The implementation doesn't accept null values. Generally
speaking, the parameters of all the public methods must have a value otherwise a NullPointerException
is
thrown.- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleSoftCache
(Map<K, SoftReference<V>> delegate) Constructs aSimpleSoftCache
with the given underlying cache. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
computeIfAbsent
(K key, Function<? super K, ? extends V> mappingFunction) computeIfPresent
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
void
forEach
(BiConsumer<? super K, ? super V> action) boolean
isEmpty()
Returns true if this map contains no key-value mappings without considering if the soft references still have a referent set for the sake of simplicity and efficiency.keySet()
void
putIfAbsent
(K key, V value) boolean
boolean
void
replaceAll
(BiFunction<? super K, ? super V, ? extends V> function) int
size()
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.Map
equals, getOrDefault, hashCode
-
Constructor Details
-
SimpleSoftCache
Constructs aSimpleSoftCache
with the given underlying cache.- Parameters:
delegate
- the underlying cache to which the modifications are applied to. Be aware that the implementation of the provided map must accept concurrent modifications to allow lazy evictions of empty references.
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty()Returns true if this map contains no key-value mappings without considering if the soft references still have a referent set for the sake of simplicity and efficiency. -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
forEach
-
replaceAll
- Specified by:
replaceAll
in interfaceMap<K,
V>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<K,
V>
-
remove
-
replace
-
replace
-
computeIfAbsent
- Specified by:
computeIfAbsent
in interfaceMap<K,
V>
-
computeIfPresent
- Specified by:
computeIfPresent
in interfaceMap<K,
V>
-
compute
-
merge
-