Class LRUCache

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

    public class LRUCache
    extends com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache

    LRU (Least Recently Used) algorithm for the cache.

    Implementation based on the LRUCache class.
    Since:
    8.0.0
    Version:
    $Revision: 17047 $ $Date: 2015-03-03 11:22:22 -0300 (Tue, 03 Mar 2015) $
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache

        com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.Entry, com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.HashIterator, com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.KeyIterator, com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.ValueIterator
      • 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>
    • Field Summary

      • Fields inherited from class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache

        barrierLock, count, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_MAX_ENTRIES, entrySet, groups, keySet, lastWrite, loadFactor, maxEntries, memoryCaching, NULL, persistenceListener, table, threshold, UNLIMITED, unlimitedDiskCache, values
    • Constructor Summary

      Constructors 
      Constructor Description
      LRUCache()
      Constructs an LRU Cache.
      LRUCache​(int capacity)
      Constructors a LRU Cache of the specified capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void itemPut​(java.lang.Object key)
      An object was put in the cache.
      protected void itemRemoved​(java.lang.Object key)
      Remove specified key since that object has been removed from the cache.
      protected void itemRetrieved​(java.lang.Object key)
      An item was retrieved from the list.
      protected java.lang.Object removeItem()
      An item needs to be removed from the cache.
      • Methods inherited from class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache

        capacity, clear, clone, contains, containsKey, containsValue, elements, entrySet, findAndRemoveEntry, get, getGroup, getGroupForReading, getGroupsForReading, getMaxEntries, getPersistenceListener, getTableForReading, isEmpty, isMemoryCaching, isOverflowPersistence, isUnlimitedDiskCache, keys, keySet, loadFactor, persistClear, persistRemove, persistRemoveGroup, persistRetrieve, persistRetrieveGroup, persistStore, persistStoreGroup, put, putAll, recordModification, rehash, remove, removeForce, setMaxEntries, setMemoryCaching, setOverflowPersistence, setPersistenceListener, setUnlimitedDiskCache, size, sput, sremove, values
      • 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, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • LRUCache

        public LRUCache()
        Constructs an LRU Cache.
        Since:
        8.0.0
      • LRUCache

        public LRUCache​(int capacity)
        Constructors a LRU Cache of the specified capacity.
        Parameters:
        capacity - The maximum cache capacity.
        Since:
        8.0.0
    • Method Detail

      • itemRetrieved

        protected void itemRetrieved​(java.lang.Object key)
        An item was retrieved from the list. The LRU implementation moves the retrieved item's key to the front of the list.
        Specified by:
        itemRetrieved in class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
        Parameters:
        key - The cache key of the item that was retrieved.
        Since:
        8.0.0
      • itemPut

        protected void itemPut​(java.lang.Object key)
        An object was put in the cache. This implementation adds/moves the key to the end of the list.
        Specified by:
        itemPut in class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
        Parameters:
        key - The cache key of the item that was put.
        Since:
        8.0.0
      • removeItem

        protected java.lang.Object removeItem()
        An item needs to be removed from the cache. The LRU implementation removes the first element in the list (ie, the item that was least-recently accessed).
        Specified by:
        removeItem in class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
        Returns:
        The key of whichever item was removed.
        Since:
        8.0.0
      • itemRemoved

        protected void itemRemoved​(java.lang.Object key)
        Remove specified key since that object has been removed from the cache.
        Specified by:
        itemRemoved in class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
        Parameters:
        key - The cache key of the item that was removed.
        Since:
        8.0.0