java.lang.Object
tools.jackson.databind.util.SimpleLookupCache<K,V>
- All Implemented Interfaces:
Serializable,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 intprotected final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Method for removing all contents this cache has.voidcontents(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 Objectintsize()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:LookupCacheMethod needed for creating clones but without contents.- Specified by:
emptyCopyin interfaceLookupCache<K,V>
-
snapshot
- Specified by:
snapshotin interfaceSnapshottable<K>
-
put
- Specified by:
putin interfaceLookupCache<K,V>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceLookupCache<K,V>
-
get
- Specified by:
getin interfaceLookupCache<K,V> - Returns:
- value associated with key (can return null)
-
clear
public void clear()Description copied from interface:LookupCacheMethod for removing all contents this cache has.- Specified by:
clearin interfaceLookupCache<K,V>
-
size
public int size()- Specified by:
sizein 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:LookupCacheMethod to apply operation on cache contents without exposing them.Default implementation throws
UnsupportedOperationException. Implementations are required to override this method.- Specified by:
contentsin interfaceLookupCache<K,V> - Parameters:
consumer- Operation to apply on cache contents.
-
readResolve
-