org.enhydra.jdbc.util
Class LRUCache

java.lang.Object
  extended by org.enhydra.jdbc.util.LRUCache
Direct Known Subclasses:
PreparedStatementCache

public class LRUCache
extends java.lang.Object

Simple implementation of a cache, using Least Recently Used algorithm for discarding members when the cache fills up


Field Summary
 Logger log
           
 
Constructor Summary
LRUCache(int maxSize)
          Constructor
 
Method Summary
 int cacheSize()
           
 void cleanupAll()
           
protected  void cleanupObject(java.lang.Object o)
          Override this method to do special cleanup on an object, such as closing a statement or a connection
 java.lang.Object get(java.lang.Object key)
          Gets an object from the cache.
 int LRUSize()
           
 void put(java.lang.Object key, java.lang.Object value)
          Puts a new object in the cache.
 java.lang.Object remove(java.lang.Object key)
          Removes the object from the cache and the lru list
 void resize(int newSize)
          Resize the cache
 void setLogger(Logger alog)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public Logger log
Constructor Detail

LRUCache

public LRUCache(int maxSize)
Constructor

Method Detail

LRUSize

public int LRUSize()

cacheSize

public int cacheSize()

put

public void put(java.lang.Object key,
                java.lang.Object value)
Puts a new object in the cache. If the cache is full, it removes the least recently used object. The new object becomes the most recently used object.


get

public java.lang.Object get(java.lang.Object key)
Gets an object from the cache. This object is set to be the most recenty used


remove

public java.lang.Object remove(java.lang.Object key)
Removes the object from the cache and the lru list


resize

public void resize(int newSize)
Resize the cache


cleanupObject

protected void cleanupObject(java.lang.Object o)
Override this method to do special cleanup on an object, such as closing a statement or a connection


cleanupAll

public void cleanupAll()

setLogger

public void setLogger(Logger alog)