Class LRUCache<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
com.renomad.minum.utils.LRUCache<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, SequencedMap<K,V>

public final class LRUCache<K,V> extends LinkedHashMap<K,V>
A simple Least-Recently Used Cache See LRU
See Also:
  • Method Details

    • removeEldestEntry

      protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
      Overrides:
      removeEldestEntry in class LinkedHashMap<K,V>
    • getLruCache

      public static <K, V> Map<K,V> getLruCache()
      Builds a map that functions as a least-recently used cache. Sets the max size to DEFAULT_MAX_ENTRIES. If you want to specify the max size, use the constructor at getLruCache(int)
      Make sure, when using this, to assign it to a fully-defined type, e.g. Map<String, String> foo = getLruCache() This is necessary since we provide this as a generic method, and the assignment is what enables Java to determine what types to build.
    • getLruCache

      public static <K, V> Map<K,V> getLruCache(int maxSize)
      Creates an LRUCache, allowing you to specify the max size. Alternately, see getLruCache().
      Make sure, when using this, to assign it to a fully-defined type, e.g. Map<String, String> foo = getLruCache(2) This is necessary since we provide this as a generic method, and the assignment is what enables Java to determine what types to build.