public class CachedLookup extends ProxyLookup
A Lookup that lazily caches the results of successful lookups performed by another instance.
  • Constructor Details

    • CachedLookup

      public CachedLookup(Lookup nestedLookup, Integer maxEntries, Scheduler resetSchedule)
      Creates a new CachedLookup.
      Parameters:
      nestedLookup - the underlying lookup to use for cache misses.
      maxEntries - the maximum number of results to cache or null if there should be no limit.
      resetSchedule - the scheduler used to clear/remove all cached entries or null if the cache should never be cleared.
    • CachedLookup

      public CachedLookup(Lookup nestedLookup, int maxEntries)
      Creates a new limited CachedLookup that never clears itself.
      Parameters:
      nestedLookup - the underlying lookup to use for cache misses.
      maxEntries - the maximum number of results to cache or null if there should be no limit.
    • CachedLookup

      public CachedLookup(Lookup nestedLookup)
      Creates a new CachedLookup that has no limit and never clears itself.
  • Method Details

    • getEntries

      public int getEntries()
      Returns the number of cached elements.
    • getMaxEntries

      public Integer getMaxEntries()
      Returns the maximum number of results to cache or null if there is no limit.
    • getResetSchedule

      public Scheduler getResetSchedule()
      Returns the schedule for clearing all cached results or null if the cache is never cleared.
    • getHits

      public long getHits()
      Returns the number of lookup requests where the results were already cached.
    • getMisses

      public long getMisses()
      Returns the number of lookup requests where the results were not already cached and the underlying lookup was used.
    • getRequests

      public long getRequests()
      Returns the number of lookup requests made on this cache (sum of getHits() and getMisses()).
    • clear

      public void clear()
      Removes all cached results; the hit and miss counts are not reset.
    • get

      public RecordList get(Object... args)
      Description copied from class: Lookup
      Returns the records that match the supplied composite lookup key.

      Contract for subclasses (see also docs/authoring/Lookup.md):

      • Called once per source record by LookupTransformer; keep it fast.
      • Return an empty RecordList when no match is found. null is also tolerated by LookupTransformer for backward compatibility, but new code should prefer an empty list for clearer semantics.
      • Do not mutate the supplied keys; they are owned by the caller.
      Overrides:
      get in class ProxyLookup
    • toString

      public String toString()
      Overrides:
      toString in class Object