public class LRUCache<K,V> extends Object implements Map<K,V>, com.github.benmanes.caffeine.cache.RemovalListener<K,V>, Serializable
Service
then this implementation will on eviction
invoke the Service.stop()
method, to auto-stop the service.
Use LRUCacheFactory
to create a new instance (do not use the constructor).LRUCacheFactory
,
LRUSoftCache
,
LRUWeakCache
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected LongAdder |
evicted |
protected LongAdder |
hits |
protected LongAdder |
misses |
Constructor and Description |
---|
LRUCache(int maximumCacheSize)
Constructs an empty LRUCache instance with the
specified maximumCacheSize, and will stop on eviction.
|
LRUCache(int initialCapacity,
int maximumCacheSize)
Constructs an empty LRUCache instance with the
specified initial capacity, maximumCacheSize, and will stop on eviction.
|
LRUCache(int initialCapacity,
int maximumCacheSize,
boolean stopOnEviction)
Constructs an empty LRUCache instance with the
specified initial capacity, maximumCacheSize,load factor and ordering mode.
|
LRUCache(int initialCapacity,
int maximumCacheSize,
boolean stopOnEviction,
boolean soft,
boolean weak,
boolean syncListener)
Constructs an empty LRUCache instance with the
specified initial capacity, maximumCacheSize,load factor and ordering mode.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanUp() |
void |
clear() |
boolean |
containsKey(Object o) |
boolean |
containsValue(Object o) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object o) |
long |
getEvicted()
Gets the number of evicted entries.
|
long |
getHits()
Gets the number of cache hits
|
int |
getMaxCacheSize()
Returns the maxCacheSize.
|
long |
getMisses()
Gets the number of cache misses.
|
boolean |
isEmpty() |
Set<K> |
keySet() |
void |
onRemoval(K key,
V value,
com.github.benmanes.caffeine.cache.RemovalCause cause) |
V |
put(K k,
V v) |
void |
putAll(Map<? extends K,? extends V> map) |
V |
remove(Object o) |
void |
resetStatistics()
Rest the cache statistics such as hits and misses.
|
int |
size() |
String |
toString() |
Collection<V> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public LRUCache(int maximumCacheSize)
maximumCacheSize
- the max capacity.IllegalArgumentException
- if the initial capacity is negativepublic LRUCache(int initialCapacity, int maximumCacheSize)
initialCapacity
- the initial capacity.maximumCacheSize
- the max capacity.IllegalArgumentException
- if the initial capacity is negativepublic LRUCache(int initialCapacity, int maximumCacheSize, boolean stopOnEviction)
initialCapacity
- the initial capacity.maximumCacheSize
- the max capacity.stopOnEviction
- whether to stop service on eviction.IllegalArgumentException
- if the initial capacity is negativepublic LRUCache(int initialCapacity, int maximumCacheSize, boolean stopOnEviction, boolean soft, boolean weak, boolean syncListener)
initialCapacity
- the initial capacity.maximumCacheSize
- the max capacity.stopOnEviction
- whether to stop service on eviction.soft
- whether to use soft values a soft cache (default is false)weak
- whether to use weak keys/values as a weak cache (default is false)syncListener
- whether to use synchronous call for the eviction listener (default is false)IllegalArgumentException
- if the initial capacity is negativepublic boolean containsKey(Object o)
containsKey
in interface Map<K,V>
public boolean containsValue(Object o)
containsValue
in interface Map<K,V>
public void onRemoval(K key, V value, com.github.benmanes.caffeine.cache.RemovalCause cause)
public long getHits()
public long getMisses()
public long getEvicted()
public int getMaxCacheSize()
public void resetStatistics()
public void cleanUp()
Apache Camel