dsto.dfc.collections.cache
Class CacheLRU

java.lang.Object
  extended by dsto.dfc.collections.cache.AbstractCache
      extended by dsto.dfc.collections.cache.CacheLRU
All Implemented Interfaces:
Cache, Serializable

public class CacheLRU
extends AbstractCache

This class is a GenericCache subclass implementing an LRU (Least Recently Used) cache replacement policy. In other words, values are added to the cache until it becomes full. Once the cache is full, when a new value is added to the cache, it replaces the least recently used value currently in the cache. This is probably the best general purpose cache replacement policy.

Since:
1.0
Version:
@version@
Author:
Daniel F. Savarese
See Also:
Serialized Form

Field Summary
 
Fields inherited from class dsto.dfc.collections.cache.AbstractCache
cache, DEFAULT_CAPACITY, numEntries, table
 
Constructor Summary
CacheLRU()
          Same as:
CacheLRU(int capacity)
          Creates a CacheLRU instance with a given cache capacity.
 
Method Summary
 Object get(Object key)
           
 Object put(Object key, Object value)
          Adds a value to the cache.
 
Methods inherited from class dsto.dfc.collections.cache.AbstractCache
capacity, isFull, keys, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheLRU

public CacheLRU(int capacity)
Creates a CacheLRU instance with a given cache capacity.

Parameters:
capacity - The capacity of the cache.

CacheLRU

public CacheLRU()
Same as:
  CacheLRU(GenericCache.DEFAULT_CAPACITY);
 

Method Detail

get

public Object get(Object key)
Specified by:
get in interface Cache
Overrides:
get in class AbstractCache

put

public Object put(Object key,
                  Object value)
Adds a value to the cache. If the cache is full, when a new value is added to the cache, it replaces the first of the current values in the cache to have been added (i.e., FIFO).

Specified by:
put in interface Cache
Specified by:
put in class AbstractCache
Parameters:
key - The key referencing the value added to the cache.
value - The value to add to the cache.
Returns:
The object that this one replaced, if any, within the cache.


Copyright © 2008 Commonwealth of Australia