Class MetaCache

java.lang.Object
org.apache.commons.jexl3.internal.MetaCache

final class MetaCache extends Object
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 Details

  • 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

      <K, V> JexlCache<K,V> createCache(int capacity)
    • 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.