java.lang.Object
org.apache.lucene.facet.taxonomy.writercache.NameIntCacheLRU
Direct Known Subclasses:
NameHashIntCacheLRU

class NameIntCacheLRU extends Object
An LRU cache of mapping from name to int. Used to cache Ordinals of category paths.
  • Field Details

    • cache

      private HashMap<Object,Integer> cache
    • nMisses

      long nMisses
    • nHits

      long nHits
    • maxCacheSize

      private int maxCacheSize
  • Constructor Details

    • NameIntCacheLRU

      NameIntCacheLRU(int maxCacheSize)
  • Method Details

    • getMaxSize

      public int getMaxSize()
      Maximum number of cache entries before eviction.
    • getSize

      public int getSize()
      Number of entries currently in the cache.
    • createCache

      private void createCache(int maxSize)
    • get

      Integer get(FacetLabel name)
    • key

      Object key(FacetLabel name)
      Subclasses can override this to provide caching by e.g. hash of the string.
    • key

      Object key(FacetLabel name, int prefixLen)
    • put

      boolean put(FacetLabel name, Integer val)
      Add a new value to cache. Return true if cache became full and some room need to be made.
    • put

      boolean put(FacetLabel name, int prefixLen, Integer val)
    • isCacheFull

      private boolean isCacheFull()
    • clear

      void clear()
    • stats

      String stats()
    • makeRoomLRU

      boolean makeRoomLRU()
      If cache is full remove least recently used entries from cache. Return true if anything was removed, false otherwise.

      See comment in DirectoryTaxonomyWriter.addToCache(CategoryPath, int) for an explanation why we clean 1/3rd of the cache, and not just one entry.