com.fasterxml.jackson.databind.util

## Class LRUMap<K,V>

- java.lang.Object
- - com.fasterxml.jackson.databind.util.LRUMap<K,V>

All Implemented Interfaces:
  LookupCache<K,V>, Serializable

    public class LRUMap<K,V>
    extends Object
    implements LookupCache<K,V>, 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.

Snce 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

### Field Summary

Fields
`protected int` `_initialEntries`
`protected PrivateMaxEntriesMap<K,V>` `_map`
`protected int` `_maxEntries`

### Constructor Summary

Constructors
Constructor and Description
`LRUMap(int initialEntries, int maxEntries)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `clear()` Method for removing all contents this cache has.
`void` `contents(BiConsumer<K,V> consumer)`
`V` `get(Object key)` NOTE: key is of type Object only to retain binary backwards-compatibility
`V` `put(K key, V value)`
`V` `putIfAbsent(K key, V value)`
`protected Object` `readResolve()`
`int` `size()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### _initialEntries

    protected final int _initialEntries

#### _maxEntries

    protected final int _maxEntries

#### _map

    protected final transient PrivateMaxEntriesMap<K,V> _map

### Constructor Detail

#### LRUMap

    public LRUMap(int initialEntries,
                  int maxEntries)

### Method Detail

#### put

    public V put(K key,
                 V value)

Specified by:
  `put` in interface `LookupCache<K,V>`

#### putIfAbsent

    public V putIfAbsent(K key,
                         V value)

Specified by:
  `putIfAbsent` in interface `LookupCache<K,V>`
Since:
  2.5

#### get

    public V get(Object key)

Description copied from interface: `LookupCache`
NOTE: key is of type Object only to retain binary backwards-compatibility

Specified by:
  `get` in interface `LookupCache<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 interface `LookupCache<K,V>`

#### size

    public int size()

Specified by:
  `size` in interface `LookupCache<K,V>`
Returns:
  Number of entries currently in cache: may be approximate, only to be used for diagnostics, metrics reporting

#### contents

    public void contents(BiConsumer<K,V> consumer)

#### readResolve

    protected Object readResolve()