Package 

Class LRUCache

  • All Implemented Interfaces:
    java.io.Serializable , java.lang.Cloneable , java.util.Map

    
    public class LRUCache<K, V>
    extends LinkedHashMap<K, V>
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      LRUCache(int cacheSize) Initializes a LRUCache with a given size using insertion order.
      LRUCache(int cacheSize, boolean accessOrder) Initializes a LRUCache with a given size using either insertion or access order depending on accessOrder.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static <T> Set<T> lruSet(int cacheSize, boolean accessOrder) Creates a new LRU set.
      Map.Entry<K, V> eldest()
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.Map

        copyOf, entry, equals, hashCode, of, ofEntries
      • Methods inherited from class java.util.AbstractMap

        toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LRUCache

        LRUCache(int cacheSize)
        Initializes a LRUCache with a given size using insertion order.
        Parameters:
        cacheSize - the maximum number of entries.
      • LRUCache

        LRUCache(int cacheSize, boolean accessOrder)
        Initializes a LRUCache with a given size using either insertion or access order depending on accessOrder.
        Parameters:
        cacheSize - the maximum number of entries.
        accessOrder - true to use access order, and false to use insertion order.
    • Method Detail

      • lruSet

         static <T> Set<T> lruSet(int cacheSize, boolean accessOrder)

        Creates a new LRU set. For a set with insertion order (accessOrder = false), only inserting new elements in the set is taken into account. With access order, any insertion (even for elements already in the set) "touches" them.

        Parameters:
        cacheSize - the maximum number of entries.
        accessOrder - true to use access order, and false to use insertion order.