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 aSimpleSoftCachewith the given underlying cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()voidforEach(BiConsumer<? super K, ? super V> action) booleanisEmpty()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()voidputIfAbsent(K key, V value) booleanbooleanvoidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) intsize()values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
equals, getOrDefault, hashCode
-
Constructor Details
-
SimpleSoftCache
Constructs aSimpleSoftCachewith 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:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
forEach
-
replaceAll
- Specified by:
replaceAllin interfaceMap<K,V>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<K,V>
-
remove
-
replace
-
replace
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<K,V>
-
computeIfPresent
- Specified by:
computeIfPresentin interfaceMap<K,V>
-
compute
-
merge
-