Class LocalAsyncCache.AbstractCacheView<K,V>
- All Implemented Interfaces:
Cache<K,
,V> Serializable
- Direct Known Subclasses:
LocalAsyncCache.CacheView
,LocalAsyncLoadingCache.LoadingCacheView
- Enclosing interface:
LocalAsyncCache<K,
V>
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()
Returns a view of the entries stored in this cache as a thread-safe map.(package private) abstract LocalAsyncCache
<K, V> void
cleanUp()
Performs any pending maintenance operations needed by the cache.long
Returns the approximate number of entries in this cache.Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
if necessary.Returns a map of the values associated with thekeys
, creating or retrieving those values if necessary.getAllPresent
(Iterable<?> keys) Returns a map of the values associated with thekeys
in this cache.@Nullable V
getIfPresent
(Object key) Returns the value associated with thekey
in this cache, ornull
if there is no cached value for thekey
.void
invalidate
(Object key) Discards any cached value for thekey
.void
Discards all entries in the cache.void
invalidateAll
(Iterable<?> keys) Discards any cached values for thekeys
.policy()
Returns access to inspect and perform low-level operations on this cache based on its runtime characteristics.void
Associates thevalue
with thekey
in this cache.void
Copies all of the mappings from the specified map to the cache.protected static <T> T
resolve
(CompletableFuture<T> future) stats()
Returns a current snapshot of this cache's cumulative statistics.
-
Field Details
-
asMapView
-
-
Constructor Details
-
AbstractCacheView
public AbstractCacheView()
-
-
Method Details
-
asyncCache
-
getIfPresent
Description copied from interface:Cache
Returns the value associated with thekey
in this cache, ornull
if there is no cached value for thekey
.- Specified by:
getIfPresent
in interfaceCache<K,
V> - Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this cache contains no mapping for the key
-
getAllPresent
Description copied from interface:Cache
Returns a map of the values associated with thekeys
in this cache. The returned map will only contain entries which are already present in the cache.Note that duplicate elements in
keys
, as determined byObject.equals(java.lang.Object)
, will be ignored.- Specified by:
getAllPresent
in interfaceCache<K,
V> - Parameters:
keys
- the keys whose associated values are to be returned- Returns:
- the unmodifiable mapping of keys to values for the specified keys found in this cache
-
get
Description copied from interface:Cache
Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
if necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern.If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this cache unless
null
. The entire method invocation is performed atomically, so the function is applied at most once per key. Some attempted update operations on this cache by other threads may be blocked while the computation is in progress, so the computation should be short and simple, and must not attempt to update any other mappings of this cache.Warning: as with
CacheLoader.load(K)
,mappingFunction
must not attempt to update any other mappings of this cache. -
getAll
public Map<K,V> getAll(Iterable<? extends K> keys, Function<Iterable<? extends K>, Map<K, V>> mappingFunction) Description copied from interface:Cache
Returns a map of the values associated with thekeys
, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with the newly loaded entries; it will never contain null keys or values.A single request to the
mappingFunction
is performed for all keys which are not already present in the cache. All entries returned bymappingFunction
will be stored in the cache, over-writing any previously cached values. If another call toCache.get(K, java.util.function.Function<? super K, ? extends V>)
tries to load the value for a key inkeys
, implementations may either have that thread load the entry or simply wait for this thread to finish and return the loaded value. In the case of overlapping non-blocking loads, the last load to complete will replace the existing entry. Note that multiple threads can concurrently load values for distinct keys. Any loaded values for keys that were not specifically requested will not be returned, but will be stored in the cache.Note that duplicate elements in
keys
, as determined byObject.equals(java.lang.Object)
, will be ignored. -
resolve
- Throws:
Error
-
put
Description copied from interface:Cache
Associates thevalue
with thekey
in this cache. If the cache previously contained a value associated with thekey
, the old value is replaced by the newvalue
.Prefer
Cache.get(Object, Function)
when using the conventional "if cached, return; otherwise create, cache and return" pattern. -
putAll
Description copied from interface:Cache
Copies all of the mappings from the specified map to the cache. The effect of this call is equivalent to that of callingput(k, v)
on this map once for each mapping from keyk
to valuev
in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. -
invalidate
Description copied from interface:Cache
Discards any cached value for thekey
. The behavior of this operation is undefined for an entry that is being loaded (or reloaded) and is otherwise not present.- Specified by:
invalidate
in interfaceCache<K,
V> - Parameters:
key
- the key whose mapping is to be removed from the cache
-
invalidateAll
Description copied from interface:Cache
Discards any cached values for thekeys
. The behavior of this operation is undefined for an entry that is being loaded (or reloaded) and is otherwise not present.- Specified by:
invalidateAll
in interfaceCache<K,
V> - Parameters:
keys
- the keys whose associated values are to be removed
-
invalidateAll
public void invalidateAll()Description copied from interface:Cache
Discards all entries in the cache. The behavior of this operation is undefined for an entry that is being loaded (or reloaded) and is otherwise not present.- Specified by:
invalidateAll
in interfaceCache<K,
V>
-
estimatedSize
public long estimatedSize()Description copied from interface:Cache
Returns the approximate number of entries in this cache. The value returned is an estimate; the actual count may differ if there are concurrent insertions or removals, or if some entries are pending removal due to expiration or weak/soft reference collection. In the case of stale entries this inaccuracy can be mitigated by performing aCache.cleanUp()
first.- Specified by:
estimatedSize
in interfaceCache<K,
V> - Returns:
- the estimated number of mappings
-
stats
Description copied from interface:Cache
Returns a current snapshot of this cache's cumulative statistics. All statistics are initialized to zero, and are monotonically increasing over the lifetime of the cache.Due to the performance penalty of maintaining statistics, some implementations may not record the usage history immediately or at all.
-
cleanUp
public void cleanUp()Description copied from interface:Cache
Performs any pending maintenance operations needed by the cache. Exactly which activities are performed -- if any -- is implementation-dependent. -
policy
Description copied from interface:Cache
Returns access to inspect and perform low-level operations on this cache based on its runtime characteristics. These operations are optional and dependent on how the cache was constructed and what abilities the implementation exposes. -
asMap
Description copied from interface:Cache
Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to the map directly affect the cache.A computation operation, such as
ConcurrentMap.compute(K, java.util.function.BiFunction<? super K, ? super V, ? extends V>)
, performs the entire method invocation atomically, so the function is applied at most once per key. Some attempted update operations by other threads may be blocked while computation is in progress. The computation must not attempt to update any other mappings of this cache.Iterators from the returned map are at least weakly consistent: they are safe for concurrent use, but if the cache is modified (including by eviction) after the iterator is created, it is undefined which of the changes (if any) will be reflected in that iterator.
-