java.lang.Object
tools.jackson.databind.util.SimpleLookupCache<K,V>
- All Implemented Interfaces:
Serializable
,tools.jackson.core.util.Snapshottable<LookupCache<K,
,V>> LookupCache<K,
V>
Synchronized cache with bounded size: used for reusing lookup values
and lazily instantiated reusable items.
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 initial and maximum size of the contents.
The implementation evicts the least recently used
entry when max size is reached; this is implemented by the backing
PrivateMaxEntriesMap
implementation.
Implementation is thread-safe and does NOT require external synchronization
NOTE: in Jackson 2.x this class was named com.fasterxml.jackson.databind.util.LRUMap
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int
protected final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Method for removing all contents this cache has.void
contents
(BiConsumer<K, V> consumer) Method to apply operation on cache contents without exposing them.Method needed for creating clones but without contents.putIfAbsent
(K key, V value) protected Object
int
size()
snapshot()
-
Field Details
-
_initialEntries
protected final int _initialEntries -
_maxEntries
protected final int _maxEntries -
_map
-
-
Constructor Details
-
SimpleLookupCache
public SimpleLookupCache(int initialEntries, int maxEntries)
-
-
Method Details
-
emptyCopy
Description copied from interface:LookupCache
Method needed for creating clones but without contents.- Specified by:
emptyCopy
in interfaceLookupCache<K,
V>
-
snapshot
- Specified by:
snapshot
in interfacetools.jackson.core.util.Snapshottable<K>
-
put
- Specified by:
put
in interfaceLookupCache<K,
V>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceLookupCache<K,
V>
-
get
- 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
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.
-
readResolve
-