Class LRUMap<K,V>
- All Implemented Interfaces:
LookupCache<K,
,V> 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.
Plan from Jackson 2.12 is to focus more on pluggability as LookupCache
and
let users, frameworks, provide their own cache implementations.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
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 final ConcurrentHashMap<K,
V> protected final int
-
Constructor Summary
-
Method Summary
-
Field Details
-
_maxEntries
protected final transient int _maxEntries -
_map
-
_jdkSerializeMaxEntries
protected transient int _jdkSerializeMaxEntriesUgly hack, to work through the requirement that _value is indeed final, and that JDK serialization won't call ctor(s) if Serializable is implemented.- Since:
- 2.1
-
-
Constructor Details
-
LRUMap
public LRUMap(int initialEntries, int maxEntries)
-
-
Method Details
-
put
- Specified by:
put
in interfaceLookupCache<K,
V>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceLookupCache<K,
V> - Since:
- 2.5
-
get
Description copied from interface:LookupCache
NOTE: key is of type Object only to retain binary backwards-compatibility- Specified by:
get
in interfaceLookupCache<K,
V> - Returns:
- value associated with key (can return null)
-
clear
public void clear()Description copied from interface:LookupCache
Method for removing all contents this cache has.- Specified by:
clear
in interfaceLookupCache<K,
V>
-
size
public int size()- Specified by:
size
in interfaceLookupCache<K,
V> - Returns:
- Number of entries currently in cache: may be approximate, only to be used for diagnostics, metrics reporting
-
readResolve
-