net.sourceforge.jtds.jdbc.cache
Class SimpleLRUCache
HashMap
net.sourceforge.jtds.jdbc.cache.SimpleLRUCache
public class SimpleLRUCache
extends HashMap
Simple LRU cache for any type of object. Implemented as an extended
HashMap
with a maximum size and an aggregated List
as LRU queue.
$Id: SimpleLRUCache.java,v 1.1 2005/04/25 11:46:56 alin_sinpalean Exp $
void | clear() - Overrides clear() to also clear the LRU list.
|
private void | freshenKey(Object key) - Moves the specified value to the top of the LRU list (the bottom of the
list is where least recently used items live).
|
Object | get(Object key) - Overrides
get() so that it also updates the LRU list.
|
Object | put(Object key, Object value) - Overrides
put() so that it also updates the LRU list.
|
Object | remove(Object key)
|
list
private final LinkedList list
LRU list.
maxCacheSize
private final int maxCacheSize
Maximum cache size.
SimpleLRUCache
public SimpleLRUCache(int maxCacheSize)
Constructs a new LRU cache instance.
maxCacheSize
- the maximum number of entries in this cache before
entries are aged off
clear
public void clear()
Overrides clear() to also clear the LRU list.
freshenKey
private void freshenKey(Object key)
Moves the specified value to the top of the LRU list (the bottom of the
list is where least recently used items live).
key
- key of the value to move to the top of the list
get
public Object get(Object key)
Overrides get()
so that it also updates the LRU list.
key
- key with which the expected value is associated
- the value to which the cache maps the specified key, or
null
if the map contains no mapping for this key
put
public Object put(Object key,
Object value)
Overrides put()
so that it also updates the LRU list.
key
- key with which the specified value is to be associatedvalue
- value to be associated with the key
- previous value associated with key or
null
if there
was no mapping for key; a null
return can also
indicate that the cache previously associated null
with the specified key
java.util.Map.put(Object, Object)
remove
public Object remove(Object key)
java.util.Map.remove(Object)
Generated on September 18 2009