ConcurrentCache (Apache Tomcat 11.0.25 API Documentation)
Description: declaration: package: org.apache.tomcat.util.collections, class: ConcurrentCache

# Class ConcurrentCache<K,V>

java.lang.Object
org.apache.tomcat.util.collections.ConcurrentCache<K,V>

Type Parameters:
  `K` - the key type
  `V` - the value type

public final class ConcurrentCache<K,V> extends Object
A thread-safe cache that uses an eden space backed by a `ConcurrentHashMap` and a long-term space backed by a `WeakHashMap`. When the eden space exceeds the configured size, its contents are promoted to the long-term space.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ConcurrentCache(int size)`
  Creates a new cache with the specified eden space size.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `V`
  `get(K k)`
  Retrieves a value from the cache.
  `void`
  `put(K k, V v)`
  Stores a value in the cache.

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### ConcurrentCache

    public ConcurrentCache(int size)
    Creates a new cache with the specified eden space size.
    Parameters:
      `size` - the maximum size of the eden space before promotion to long-term storage

- ## Method Details

  - ### get

    public V get(K k)
    Retrieves a value from the cache. If found in the long-term store, it is promoted to the eden space for faster subsequent access.
    Parameters:
      `k` - the key to look up
    Returns:
      the cached value, or `null` if not found

  - ### put

    public void put(K k, V v)
    Stores a value in the cache. If the eden space is full, all eden entries are promoted to the long-term store before adding the new entry.
    Parameters:
      `k` - the key
      `v` - the value to cache