Class LRUMap<K,V>
- java.lang.Object
-
- com.fasterxml.jackson.databind.util.LRUMap<K,V>
-
- All Implemented Interfaces:
LookupCache<K,V>
,java.io.Serializable
public class LRUMap<K,V> extends java.lang.Object implements LookupCache<K,V>, java.io.Serializable
Helper for simple bounded maps used for reusing lookup values.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.
Since Jackson 2.12, there has been pluggable
LookupCache
interface which allows users, frameworks, provide their own cache implementations.Since Jackson 2.14, the implementation
- Evicts the least recently used entry when max size is reached
- Is thread-safe and does NOT require external synchronization
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LRUMap(int initialEntries, int maxEntries)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Method for removing all contents this cache has.void
contents(java.util.function.BiConsumer<K,V> consumer)
Method to apply operation on cache contents without exposing them.LookupCache<K,V>
emptyCopy()
Method needed for creating clones but without contents.V
get(java.lang.Object key)
NOTE: key is of type Object only to retain binary backwards-compatibilityV
put(K key, V value)
V
putIfAbsent(K key, V value)
int
size()
-
-
-
Method Detail
-
emptyCopy
public LookupCache<K,V> emptyCopy()
Description copied from interface:LookupCache
Method needed for creating clones but without contents.Default implementation throws
UnsupportedOperationException
. Implementations are required to override this method.- Specified by:
emptyCopy
in interfaceLookupCache<K,V>
-
putIfAbsent
public V putIfAbsent(K key, V value)
- Specified by:
putIfAbsent
in interfaceLookupCache<K,V>
- Since:
- 2.5
-
get
public V get(java.lang.Object key)
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
-
contents
public void contents(java.util.function.BiConsumer<K,V> consumer)
Description copied from interface:LookupCache
Method to apply operation on cache contents without exposing them.Default implementation throws
UnsupportedOperationException
. Implementations are required to override this method.- Specified by:
contents
in interfaceLookupCache<K,V>
- Parameters:
consumer
- Operation to apply on cache contents.
-
-