K - the type of the key used for cache retrievalV - the type of the cached valuespublic class ConcurrentLruCache<K,V> extends Object
This implementation is backed by a ConcurrentHashMap for storing
the cached values and a ConcurrentLinkedDeque for ordering the keys
and choosing the least recently used key when the cache is at full capacity.
get(K)| Constructor and Description |
|---|
ConcurrentLruCache(int sizeLimit,
Function<K,V> generator)
Create a new cache instance with the given limit and generator function.
|
| Modifier and Type | Method and Description |
|---|---|
V |
get(K key)
Retrieve an entry from the cache, potentially triggering generation
of the value.
|
int |
size()
Return the current size of the cache.
|
int |
sizeLimit()
Return the the maximum number of entries in the cache
(0 indicates no caching, always generating a new value).
|
public ConcurrentLruCache(int sizeLimit,
Function<K,V> generator)
sizeLimit - 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 keypublic V get(K key)
key - the key to retrieve the entry forpublic int size()
sizeLimit()public int sizeLimit()
size()