Class MetaCache
java.lang.Object
org.apache.commons.jexl3.internal.MetaCache
A meta-cache that tracks multiple JexlCache instances via weak references.
Each JexlCache created by this MetaCache is held via a WeakReference, allowing it to be garbage collected as soon as no strong references exist.
This allows for collective management of multiple caches, in particular clearing all caches at once. This operation is typically called when the uberspect class loader needs to change.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IntFunction<JexlCache<?,?>> private final ReferenceQueue<JexlCache<?,?>> -
Constructor Summary
ConstructorsConstructorDescriptionMetaCache(IntFunction<JexlCache<?, ?>> factory) Constructs a MetaCache with the given cache factory. -
Method Summary
Modifier and TypeMethodDescriptionprivate intcleanUp()Cleans up all references whose referent (the cache) has been garbage collected.(package private) voidClears all caches tracked by this MetaCache.(package private) <K,V> JexlCache<K, V> createCache(int capacity) (package private) intsize()Gets the number of live caches currently tracked by this MetaCache.
-
Field Details
-
factory
-
references
-
queue
-
-
Constructor Details
-
MetaCache
MetaCache(IntFunction<JexlCache<?, ?>> factory) Constructs a MetaCache with the given cache factory.- Parameters:
factory- The factory function to create JexlCache instances given a capacity.
-
-
Method Details
-
createCache
-
clearCaches
void clearCaches()Clears all caches tracked by this MetaCache. -
cleanUp
private int cleanUp()Cleans up all references whose referent (the cache) has been garbage collected.This method must be invoked while holding the lock on
references.- Returns:
- The remaining number of caches.
-
size
int size()Gets the number of live caches currently tracked by this MetaCache.Any cache that is no longer strongly reference will get removed from the tracked set.
- Returns:
- The number of caches.
-