public class LRUMap<K,V> extends Object 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: since version 2.4.2, this is NOT an LRU-based at all; reason being that it is not possible to use JDK components that do LRU _AND_ perform well wrt synchronization on multi-core systems. So we choose efficient synchronization over potentially more efficient handling of entries.
And yes, there are efficient LRU implementations such as concurrentlinkedhashmap; but at this point we really try to keep external deps to minimum. But perhaps a shaded variant may be used one day.
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 ConcurrentHashMap<K,V> |
_map |
protected int |
_maxEntries |
Constructor and Description |
---|
LRUMap(int initialEntries,
int maxEntries) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
V |
get(Object key) |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
protected Object |
readResolve() |
int |
size() |
protected final transient int _maxEntries
protected final transient ConcurrentHashMap<K,V> _map
protected transient int _jdkSerializeMaxEntries
Copyright © 2008–2019 FasterXML. All rights reserved.