Class LruMemoryStore.SpoolingLinkedHashMap

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

    public final class LruMemoryStore.SpoolingLinkedHashMap
    extends java.util.LinkedHashMap
    An extension of LinkedHashMap which overrides removeEldestEntry(java.util.Map.Entry) to persist cache entries to the auxiliary cache before they are removed.

    This implementation also provides LRU by access order.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)
      protected boolean removeEldestEntry​(java.util.Map.Entry eldest)
      Returns true if this map should remove its eldest entry.
      • 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, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
    • Constructor Detail

      • SpoolingLinkedHashMap

        public SpoolingLinkedHashMap()
        Default constructor. Will create an initial capacity of 100, a loading of .75 and LRU by access order.
    • Method Detail

      • removeEldestEntry

        protected final boolean removeEldestEntry​(java.util.Map.Entry eldest)
        Returns true if this map should remove its eldest entry. This method is invoked by put and putAll after inserting a new entry into the map. It provides the implementer with the opportunity to remove the eldest entry each time a new one is added. This is useful if the map represents a cache: it allows the map to reduce memory consumption by deleting stale entries.

        Will return true if:

        1. the element has expired
        2. the cache size is greater than the in-memory actual. In this case we spool to disk before returning.
        Overrides:
        removeEldestEntry in class java.util.LinkedHashMap
        Parameters:
        eldest - The least recently inserted entry in the map, or if this is an access-ordered map, the least recently accessed entry. This is the entry that will be removed it this method returns true. If the map was empty prior to the put or putAll invocation resulting in this invocation, this will be the entry that was just inserted; in other words, if the map contains a single entry, the eldest entry is also the newest.
        Returns:
        true if the eldest entry should be removed from the map; false if it should be retained.
      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Specified by:
        put in interface java.util.Map
        Overrides:
        put in class java.util.HashMap