Class CachingMatcher.WithInlineEviction<S>

Type Parameters:
S - The actual matched type of this matcher.
All Implemented Interfaces:
ElementMatcher<S>, ElementMatcher.Junction<S>
Enclosing class:
CachingMatcher<T>

public static class CachingMatcher.WithInlineEviction<S> extends CachingMatcher<S>
A caching matcher with inline cache eviction.
  • Field Details

    • evictionSize

      private final int evictionSize
      The maximum amount of entries in this map before removing a random entry from the map.
  • Constructor Details

    • WithInlineEviction

      public WithInlineEviction(ElementMatcher<? super S> matcher, ConcurrentMap<? super S,Boolean> map, int evictionSize)
      Creates a new caching matcher with inlined cache eviction.
      Parameters:
      matcher - The underlying matcher to apply for non-cached targets.
      map - A map that serves as a cache for previous matches. This match is strongly referenced and can cause a memory leak if it is not evicted while keeping this matcher alive.
      evictionSize - The maximum amount of entries in this map before removing a random entry from the map.
  • Method Details

    • onCacheMiss

      protected boolean onCacheMiss(@MaybeNull S target)
      Invoked if the cache is not hit.
      Overrides:
      onCacheMiss in class CachingMatcher<S>
      Parameters:
      target - The element to be matched.
      Returns:
      true if the element is matched.