net.sourceforge.jtds.jdbc.cache
Class SimpleLRUCache
java.lang.Object
java.util.AbstractMap
java.util.HashMap
net.sourceforge.jtds.jdbc.cache.SimpleLRUCache
- All Implemented Interfaces:
- java.lang.Cloneable, java.util.Map, java.io.Serializable
- public class SimpleLRUCache
- extends java.util.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.
- Version:
- $Id: SimpleLRUCache.java,v 1.1 2005-04-25 11:46:56 alin_sinpalean Exp $
- Author:
- Brett Wooldridge
- See Also:
- Serialized Form
Nested classes inherited from class java.util.HashMap |
|
Nested classes inherited from class java.util.AbstractMap |
|
Field Summary |
private java.util.LinkedList |
list
LRU list. |
private int |
maxCacheSize
Maximum cache size. |
Fields inherited from class java.util.HashMap |
|
Fields inherited from class java.util.AbstractMap |
|
Constructor Summary |
SimpleLRUCache(int maxCacheSize)
Constructs a new LRU cache instance. |
Method Summary |
void |
clear()
Overrides clear() to also clear the LRU list. |
private void |
freshenKey(java.lang.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). |
java.lang.Object |
get(java.lang.Object key)
Overrides get() so that it also updates the LRU list. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Overrides put() so that it also updates the LRU list. |
java.lang.Object |
remove(java.lang.Object key)
|
Methods inherited from class java.util.HashMap |
clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, size, values |
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 |
maxCacheSize
private final int maxCacheSize
- Maximum cache size.
list
private final java.util.LinkedList list
- LRU list.
SimpleLRUCache
public SimpleLRUCache(int maxCacheSize)
- Constructs a new LRU cache instance.
- Parameters:
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.
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
- Overrides
put()
so that it also updates the LRU list.
- Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the key
- Returns:
- 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 - See Also:
Map.put(Object, Object)
get
public java.lang.Object get(java.lang.Object key)
- Overrides
get()
so that it also updates the LRU list.
- Parameters:
key
- key with which the expected value is associated
- Returns:
- the value to which the cache maps the specified key, or
null
if the map contains no mapping for this key
remove
public java.lang.Object remove(java.lang.Object key)
- See Also:
Map.remove(Object)
freshenKey
private void freshenKey(java.lang.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).
- Parameters:
key
- key of the value to move to the top of the list
Generated on October 27 2012