Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.oscache.base.algorithm
Class LRUCache

    java.lang.Object
      java.util.AbstractMap
          com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
              com.opensymphony.oscache.base.algorithm.LRUCache

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

public class LRUCache
extends AbstractConcurrentReadCache

LRU (Least Recently Used) algorithm for the cache.

This class tries to provide the best possible performance by first attempting to use the JDK 1.4.x `LinkedHashSet` class, followed by the Jakarta commons-collections `SequencedHashMap` class, and finally resorting to the `LinkedList` class if neither of the above classes are available. If this class has to revert to using a `LinkedList` a warning is logged since the performance penalty can be severe.

No synchronization is required in this class since the `AbstractConcurrentReadCache` already takes care of any synchronization requirements.

Version:
  $Revision: 1.3 $
Author:
  Victor Salaman, Francois Beauregard, Alain Bergevin, Chris Miller
See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache
`AbstractConcurrentReadCache.Entry, AbstractConcurrentReadCache.HashIterator, AbstractConcurrentReadCache.KeyIterator, AbstractConcurrentReadCache.ValueIterator`

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
`LRUCache()` Constructs an LRU Cache.
`LRUCache(int capacity)` Constructors a LRU Cache of the specified capacity.

Method Summary
`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, getGroupsForReading, getMaxEntries, getPersistenceListener, getTableForReading, isEmpty, isMemoryCaching, isUnlimitedDiskCache, keys, keySet, loadFactor, persistClear, persistRemove, persistRemoveGroup, persistRetrieve, persistRetrieveGroup, persistStore, persistStoreGroup, put, putAll, readObject, recordModification, rehash, remove, setMaxEntries, setMemoryCaching, setPersistenceListener, setUnlimitedDiskCache, size, sput, sremove, values, writeObject`

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
`equals, hashCode`

Constructor Detail

### LRUCache

    public LRUCache()

  Constructs an LRU Cache.

### LRUCache

    public LRUCache(int capacity)

  Constructors a LRU Cache of the specified capacity.

Parameters:
  `capacity` - The maximum cache capacity.

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 `AbstractConcurrentReadCache`
  Parameters:
    `key` - The cache key of the item that was retrieved.

### 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 `AbstractConcurrentReadCache`
  Parameters:
    `key` - The cache key of the item that was put.

### 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 `AbstractConcurrentReadCache`
  Returns:
    The key of whichever item was removed.

### 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 `AbstractConcurrentReadCache`
  Parameters:
    `key` - The cache key of the item that was removed.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| See www.opensymphony.com for more information.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD