|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap
net.sourceforge.jtds.jdbc.cache.SimpleLRUCache
public class SimpleLRUCache
Simple LRU cache for any type of object. Implemented as an extended
HashMap
with a maximum size and an aggregated List
as LRU queue.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Field Summary | |
---|---|
private java.util.LinkedList |
list
LRU list. |
private int |
maxCacheSize
Maximum cache size. |
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 |
Field Detail |
---|
private final int maxCacheSize
private final java.util.LinkedList list
Constructor Detail |
---|
public SimpleLRUCache(int maxCacheSize)
maxCacheSize
- the maximum number of entries in this cache before
entries are aged offMethod Detail |
---|
public 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 key
null
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 associated
null
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 list
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |