类 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, Harry Yang
另请参阅:
  • 字段详细资料

  • 构造器详细资料

    • 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
    • ConcurrentLruCache

      private ConcurrentLruCache(int capacity, Function<K,V> generator, int concurrencyLevel)
  • 方法详细资料

    • 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
    • put

      private void put(K key, V value)
    • processRead

      private void processRead(ConcurrentLruCache.Node<K,V> node)
    • processWrite

      private void processWrite(Runnable task)
    • drainOperations

      private void drainOperations()
    • 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.
    • markAsRemoved

      private void markAsRemoved(ConcurrentLruCache.Node<K,V> node)
      Transition the node to the removed state and decrement the current size of the 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
    • markForRemoval

      private void markForRemoval(ConcurrentLruCache.Node<K,V> node)
      Transition the node from the active state to the pending removal state, if the transition is valid.