org.apache.turbine.util
Class BufferCache

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--org.apache.turbine.util.SequencedHashtable
                    |
                    +--org.apache.turbine.util.BufferCache
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class BufferCache
extends SequencedHashtable

A fixed length object cache implementing the LRU algorithm. Convenient for buffering recently used objects.

Version:
$Id$
Author:
Daniel Rall
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
private static int DEFAULT_MAX_SIZE
          The default maximum cache size.
private  int maxSize
          The size of the cache.
 
Fields inherited from class org.apache.turbine.util.SequencedHashtable
keySequence, UKNOWN_INDEX
 
Fields inherited from class java.util.Hashtable
count, emptyEnumerator, emptyIterator, ENTRIES, entrySet, KEYS, keySet, loadFactor, modCount, serialVersionUID, table, threshold, values, VALUES
 
Constructor Summary
BufferCache()
          Creates a new instance with default storage buffer pre-allocated.
BufferCache(int maxSize)
          Creates a new instance with the specified storage buffer pre-allocated.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Retrieves the value associated with the provided key, freshening the sequence of the key as well.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Stores the provided key/value pair, freshening its list index if the specified key already exists.
 
Methods inherited from class org.apache.turbine.util.SequencedHashtable
clear, clone, freshenSequence, get, getValue, indexOf, iterator, lastIndexOf, putAll, remove, remove, remove, values
 
Methods inherited from class java.util.Hashtable
, contains, containsKey, containsValue, elements, entrySet, equals, getEnumeration, getIterator, hashCode, isEmpty, keys, keySet, readObject, rehash, size, toString, writeObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

DEFAULT_MAX_SIZE

private static final int DEFAULT_MAX_SIZE
The default maximum cache size.

maxSize

private int maxSize
The size of the cache. The newest elements in the sequence are kept toward the end.
Constructor Detail

BufferCache

public BufferCache()
Creates a new instance with default storage buffer pre-allocated.

BufferCache

public BufferCache(int maxSize)
Creates a new instance with the specified storage buffer pre-allocated.
Parameters:
maxSize - The maximum size of the cache.
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Stores the provided key/value pair, freshening its list index if the specified key already exists.
Overrides:
put in class SequencedHashtable
Parameters:
key - The key to the provided value.
value - The value to store.
Returns:
The previous value for the specified key, or null if none.

get

public java.lang.Object get(java.lang.Object key)
Retrieves the value associated with the provided key, freshening the sequence of the key as well.
Overrides:
get in class java.util.Hashtable
Parameters:
key - The key whose value to retrieve.
Returns:
The keyed value.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.