public class LRUMap<K,V> extends LinkedHashMap<K,V> implements Serializable
Note that serialization behavior is such that contents are NOT serialized, on assumption that all use cases are for caching where persistence does not make sense. The only thing serialized is the cache size of Map.
NOTE: the only reason we extend LinkedHashMap
instead of aggregating
it is that this way we can override removeEldestEntry(java.util.Map.Entry<K, V>)
.
Access, however, MUST be done using single-element access methods (or matching
xxxAll()
methods that call them); access via iterators are not
guaranteed to work.
NOTE: since version 2.4, uses ReentrantReadWriteLock
to improve
concurrent access.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected int |
_jdkSerializeMaxEntries
Ugly hack, to work through the requirement that _value is indeed final,
and that JDK serialization won't call ctor(s) if Serializable is implemented.
|
protected int |
_maxEntries |
protected Lock |
_readLock |
protected Lock |
_writeLock |
Constructor and Description |
---|
LRUMap(int initialEntries,
int maxEntries) |
Modifier and Type | Method and Description |
---|---|
V |
get(Object key) |
V |
put(K key,
V value) |
protected Object |
readResolve() |
V |
remove(Object key) |
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest) |
clear, containsValue
clone, containsKey, entrySet, isEmpty, keySet, putAll, size, values
equals, hashCode, toString
protected final transient Lock _readLock
protected final transient Lock _writeLock
protected final transient int _maxEntries
protected transient int _jdkSerializeMaxEntries
Copyright © 2014 FasterXML. All Rights Reserved.