Class WeakKeySoftValueLoadingCache<K,V>
- java.lang.Object
-
- co.elastic.apm.agent.cache.WeakKeySoftValueLoadingCache<K,V>
-
- Type Parameters:
K- the key typeV- the value type
public class WeakKeySoftValueLoadingCache<K,V> extends java.lang.ObjectThis cache is useful in situations when hard referencing the cache key and the value would otherwise lead to memory or class loader leaks.Use use-case is storing a value, like a
ClassorMethodHandlewhich is specific to a certainClassLoader. Holding a strong reference to any of these from the agent code would lead to classloader leaks. That's why the key is wrapped in aWeakReferenceand the value is wrapped in aSoftReference.An otherwise not referenced
ClassLoadermight still not be collected for a longer time as usual if it is indirectly referenced by the value which is wrapped in aSoftReference. But there is no danger of OOMEs, as the softly referenced value will be collected when memory gets scarce or if it has not been accessed for some time.There can also be the situation that a value is collected although it is actually still used. In that case, the value is re-loaded transparently. For frequently accessed values that should not be the case, as a
SoftReferenceworks a bit like a LRU cache (see http://xmlandmore.blogspot.com/2014/12/jdk-8-when-softly-referenced-objects.html).If the cache key has been collected, the underlying
WeakConcurrentMapmakes sure that the map entry is deleted.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceWeakKeySoftValueLoadingCache.ValueSupplier<K,V>Supplies a value, given a key.
-
Constructor Summary
Constructors Constructor Description WeakKeySoftValueLoadingCache(WeakKeySoftValueLoadingCache.ValueSupplier<K,V> valueSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vget(K key)
-
-
-
Constructor Detail
-
WeakKeySoftValueLoadingCache
public WeakKeySoftValueLoadingCache(WeakKeySoftValueLoadingCache.ValueSupplier<K,V> valueSupplier)
-
-