类 ConcurrentLruCache<K,V>
java.lang.Object
cn.taketoday.util.ConcurrentLruCache<K,V>
- 类型参数:
K- the type of the key used for cache retrievalV- the type of the cached values, does not allow null values
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. -
方法概要
修饰符和类型方法说明intcapacity()Return the maximum number of entries in the cache.voidclear()Immediately remove all entries from this cache.booleanDetermine whether the given key is present in this cache.Retrieve an entry from the cache, potentially triggering generation of the value.booleanImmediately remove the given key and any associated value.intsize()Return the current size of the cache.
-
构造器详细资料
-
ConcurrentLruCache
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
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
Determine whether the given key is present in this cache.- 参数:
key- the key to check for- 返回:
trueif the key is present,falseif there was no matching key
-
remove
Immediately remove the given key and any associated value.- 参数:
key- the key to evict the entry for- 返回:
trueif the key was present before,falseif there was no matching key
-