类 ConcurrentLruCache<K,V>

java.lang.Object
cn.taketoday.util.ConcurrentLruCache<K,V>
类型参数:
K - the type of the key used for cache retrieval
V - the type of the cached values, does not allow null values

public final class ConcurrentLruCache<K,V> extends Object
Simple LRU (Least Recently Used) cache, bounded by a specified cache capacity.

This is a simplified, opinionated implementation of a LRU cache for internal use in Infra Framework. It is inspired from ConcurrentLinkedHashMap.

Read and write operations are internally recorded in dedicated buffers, then drained at chosen times to avoid contention.

从以下版本开始:
4.0
作者:
Brian Clozel, Ben Manes
另请参阅:
  • 构造器概要

    构造器
    构造器
    说明
    ConcurrentLruCache(int capacity, Function<K,V> generator)
    Create a new cache instance with the given capacity and generator function.
  • 方法概要

    修饰符和类型
    方法
    说明
    int
    Return the maximum number of entries in the cache.
    void
    Immediately remove all entries from this cache.
    boolean
    contains(K key)
    Determine whether the given key is present in this cache.
    get(K key)
    Retrieve an entry from the cache, potentially triggering generation of the value.
    boolean
    remove(K key)
    Immediately remove the given key and any associated value.
    int
    Return the current size of the cache.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • ConcurrentLruCache

      public ConcurrentLruCache(int capacity, Function<K,V> generator)
      Create a new cache instance with the given capacity and generator function.
      参数:
      capacity - the maximum number of entries in the cache (0 indicates no caching, always generating a new value)
      generator - a function to generate a new value for a given key
  • 方法详细资料

    • get

      public V get(K key)
      Retrieve an entry from the cache, potentially triggering generation of the value.
      参数:
      key - the key to retrieve the entry for
      返回:
      the cached or newly generated value
    • capacity

      public int capacity()
      Return the maximum number of entries in the cache.
      另请参阅:
    • size

      public int size()
      Return the current size of the cache.
      另请参阅:
    • clear

      public void clear()
      Immediately remove all entries from this cache.
    • contains

      public boolean contains(K key)
      Determine whether the given key is present in this cache.
      参数:
      key - the key to check for
      返回:
      true if the key is present, false if there was no matching key
    • remove

      public boolean remove(K key)
      Immediately remove the given key and any associated value.
      参数:
      key - the key to evict the entry for
      返回:
      true if the key was present before, false if there was no matching key