public class OnHeapLoadingCache<K,V> extends Object implements LoadingCache<K,V>
Constructor and Description |
---|
OnHeapLoadingCache(int concurrencyLevel,
int initialCapacity,
Long maximumSize,
Long expireAfterAccess,
Long expireAfterWrite) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Clean the used resources of the cache.
|
boolean |
equals(Object o) |
V |
get(K key,
Callable<? extends V> valueLoader)
Returns the value associated with
key in this cache, obtaining that value from
valueLoader if necessary. |
Map<K,V> |
getAllPresent(Iterable<K> keys)
Returns a map of the values associated with
keys in this cache. |
V |
getIfPresent(K key) |
LookupCacheStats |
getStats() |
int |
hashCode() |
void |
invalidate(K key)
Discards any cached value for key
key . |
void |
invalidateAll()
Clears the contents of the cache.
|
void |
invalidateAll(Iterable<K> keys)
Discards any cached values for keys
keys . |
boolean |
isClosed() |
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to the cache.
|
public OnHeapLoadingCache(int concurrencyLevel, int initialCapacity, Long maximumSize, Long expireAfterAccess, Long expireAfterWrite)
concurrencyLevel
- default to DEFAULT_CONCURRENCY_LEVEL
initialCapacity
- default to DEFAULT_INITIAL_CAPACITY
maximumSize
- Max number of entries that the cache can hold, When set to zero, elements will be evicted immediately after being loaded into the
cache.
When set to null, cache maximum size is infinityexpireAfterAccess
- Specifies that each entry should be automatically removed from the cache once a fixed duration
has elapsed after the entry's creation, the most recent replacement of its value, or its last
access. Access time is reset by all cache read and write operations.
No read-time-based eviction when set to null.expireAfterWrite
- Specifies that each entry should be automatically removed from the cache once a fixed duration
has elapsed after the entry's creation, or the most recent replacement of its value.
No write-time-based eviction when set to null.public V getIfPresent(K key)
getIfPresent
in interface LoadingCache<K,V>
key
- must not be null
Returns the value associated with key
in this cache, or null
if there is no
cached value for key
.
a cache miss should be counted if the key is missing.public void putAll(Map<? extends K,? extends V> m)
LoadingCache
putAll
in interface LoadingCache<K,V>
public Map<K,V> getAllPresent(Iterable<K> keys)
LoadingCache
keys
in this cache. The returned map will
only contain entries which are already present in the cache.getAllPresent
in interface LoadingCache<K,V>
public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException
LoadingCache
key
in this cache, obtaining that value from
valueLoader
if necessary. No observable state associated with this cache is modified
until loading completes.
Warning: as with CacheLoader.load(K)
, valueLoader
must not return
null
; it may either return a non-null value or throw an exception.
get
in interface LoadingCache<K,V>
ExecutionException
- if a checked exception was thrown while loading the valuepublic void invalidate(K key)
LoadingCache
key
. Eviction can be lazy or eager.invalidate
in interface LoadingCache<K,V>
public void invalidateAll(Iterable<K> keys)
LoadingCache
keys
. Eviction can be lazy or eager.invalidateAll
in interface LoadingCache<K,V>
public void invalidateAll()
LoadingCache
invalidateAll
in interface LoadingCache<K,V>
public LookupCacheStats getStats()
getStats
in interface LoadingCache<K,V>
public boolean isClosed()
isClosed
in interface LoadingCache<K,V>
public void close()
LoadingCache
close
in interface LoadingCache<K,V>
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2011–2017. All rights reserved.