net.sourceforge.jtds.jdbc.cache
public class SimpleLRUCache extends java.util.HashMap
HashMap
with a maximum size and an aggregated List
as LRU queue.Modifier and Type | Field and Description |
---|---|
private java.util.LinkedList |
list
LRU list.
|
private int |
maxCacheSize
Maximum cache size.
|
Constructor and Description |
---|
SimpleLRUCache(int maxCacheSize)
Constructs a new LRU cache instance.
|
Modifier and Type | Method and Description |
---|---|
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) |
clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, size, values
private final int maxCacheSize
private final java.util.LinkedList list
public SimpleLRUCache(int maxCacheSize)
maxCacheSize
- the maximum number of entries in this cache before
entries are aged offpublic void clear()
clear
in interface java.util.Map
clear
in class java.util.HashMap
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put()
so that it also updates the LRU list.put
in interface java.util.Map
put
in class java.util.HashMap
key
- key with which the specified value is to be associatedvalue
- value to be associated with the keynull
if there
was no mapping for key; a null
return can also
indicate that the cache previously associated null
with the specified keyMap.put(Object, Object)
public java.lang.Object get(java.lang.Object key)
get()
so that it also updates the LRU list.get
in interface java.util.Map
get
in class java.util.HashMap
key
- key with which the expected value is associatednull
if the map contains no mapping for this keypublic java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.HashMap
Map.remove(Object)
private void freshenKey(java.lang.Object key)
key
- key of the value to move to the top of the listGenerated on March 22 2014