Package 

Class LRUCache

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

    
    public class LRUCache<K, V>
    extends LinkedHashMap<K, V>
                        
    • 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 {@code accessOrder}.
    • Method Summary

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

        afterNodeAccess, afterNodeInsertion, afterNodeRemoval, clear, containsValue, entrySet, forEach, get, getOrDefault, internalWriteEntries, keySet, linkNodeLast, newNode, newTreeNode, reinitialize, removeEldestEntry, replaceAll, replacementNode, replacementTreeNode, transferLinks, values
      • Methods inherited from class java.util.HashMap

        capacity, clone, comparableClassFor, compareComparables, compute, computeIfAbsent, computeIfPresent, containsKey, getNode, hash, isEmpty, loadFactor, merge, put, putAll, putIfAbsent, putMapEntries, putVal, readObject, remove, remove, removeNode, replace, replace, resize, size, tableSizeFor, treeifyBin, writeObject
      • Methods inherited from class java.util.AbstractMap

        eq, equals, hashCode, 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 {@code accessOrder}.
        Parameters:
        cacheSize - the maximum number of entries.
        accessOrder - to use access order, and 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 ({@code 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 - to use access order, and to use insertion order.