Class ConcurrentLFUCache<K,​V>

  • All Implemented Interfaces:
    Cache<K,​V>

    public class ConcurrentLFUCache<K,​V>
    extends Object
    implements Cache<K,​V>
    A LFU cache implementation based upon ConcurrentHashMap.

    This is not a terribly efficient implementation. The tricks used in the LRU version were not directly usable, perhaps it might be possible to rewrite them with LFU in mind.

    This API is experimental and subject to change

    Since:
    solr 1.6
    • Constructor Detail

      • ConcurrentLFUCache

        public ConcurrentLFUCache​(int upperWaterMark,
                                  int lowerWaterMark,
                                  int acceptableSize,
                                  int initialSize,
                                  boolean runCleanupThread,
                                  boolean runNewThreadForCleanup,
                                  ConcurrentLFUCache.EvictionListener<K,​V> evictionListener,
                                  boolean timeDecay)
      • ConcurrentLFUCache

        public ConcurrentLFUCache​(int size,
                                  int lowerWatermark)
    • Method Detail

      • setAlive

        public void setAlive​(boolean live)
      • get

        public V get​(K key)
        Specified by:
        get in interface Cache<K,​V>
      • remove

        public V remove​(K key)
        Specified by:
        remove in interface Cache<K,​V>
      • put

        public V put​(K key,
                     V val)
        Specified by:
        put in interface Cache<K,​V>
      • getLeastUsedItems

        public Map<K,​V> getLeastUsedItems​(int n)
        Returns 'n' number of least used entries present in this cache.

        This uses a TreeSet to collect the 'n' least used items ordered by ascending hitcount and returns a LinkedHashMap containing 'n' or less than 'n' entries.

        Parameters:
        n - the number of items needed
        Returns:
        a LinkedHashMap containing 'n' or less than 'n' entries
      • getMostUsedItems

        public Map<K,​V> getMostUsedItems​(int n)
        Returns 'n' number of most used entries present in this cache.

        This uses a TreeSet to collect the 'n' most used items ordered by descending hitcount and returns a LinkedHashMap containing 'n' or less than 'n' entries.

        Parameters:
        n - the number of items needed
        Returns:
        a LinkedHashMap containing 'n' or less than 'n' entries
      • size

        public int size()
      • clear

        public void clear()
        Specified by:
        clear in interface Cache<K,​V>
      • destroy

        public void destroy()