Class CaffeineCacheImpl
- java.lang.Object
-
- io.quarkus.cache.runtime.AbstractCache
-
- io.quarkus.cache.runtime.caffeine.CaffeineCacheImpl
-
- All Implemented Interfaces:
Cache
,CaffeineCache
public class CaffeineCacheImpl extends AbstractCache implements CaffeineCache
This class is an internal Quarkus cache implementation. Do not use it explicitly from your Quarkus application. The public methods signatures may change without prior notice.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) com.github.benmanes.caffeine.cache.AsyncCache<Object,Object>
cache
-
Fields inherited from class io.quarkus.cache.runtime.AbstractCache
NULL_KEYS_NOT_SUPPORTED_MSG
-
-
Constructor Summary
Constructors Constructor Description CaffeineCacheImpl(CaffeineCacheInfo cacheInfo, boolean recordStats)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <K,V>
io.smallrye.mutiny.Uni<V>get(K key, Function<K,V> valueLoader)
Returns a lazy asynchronous action that will emit the cache value identified bykey
, obtaining that value fromvalueLoader
if necessary.CaffeineCacheInfo
getCacheInfo()
<V> CompletableFuture<V>
getIfPresent(Object key)
Returns the future associated withkey
in this cache, ornull
if there is no cached future forkey
.String
getName()
Returns the cache name.long
getSize()
io.smallrye.mutiny.Uni<Void>
invalidate(Object key)
Removes the cache entry identified bykey
from the cache.io.smallrye.mutiny.Uni<Void>
invalidateAll()
Removes all entries from the cache.Set<Object>
keySet()
Returns an unmodifiableSet
view of the keys contained in this cache.<V> void
put(Object key, CompletableFuture<V> valueFuture)
Associatesvalue
withkey
in this cache.io.smallrye.mutiny.Uni<Void>
replaceUniValue(Object key, Object emittedValue)
Replaces the cache value associated with the given key by an item emitted by aUni
.-
Methods inherited from class io.quarkus.cache.runtime.AbstractCache
as, getDefaultKey
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.quarkus.cache.Cache
as, getDefaultKey
-
-
-
-
Constructor Detail
-
CaffeineCacheImpl
public CaffeineCacheImpl(CaffeineCacheInfo cacheInfo, boolean recordStats)
-
-
Method Detail
-
get
public <K,V> io.smallrye.mutiny.Uni<V> get(K key, Function<K,V> valueLoader)
Description copied from interface:Cache
Returns a lazy asynchronous action that will emit the cache value identified bykey
, obtaining that value fromvalueLoader
if necessary.
-
getIfPresent
public <V> CompletableFuture<V> getIfPresent(Object key)
Description copied from interface:CaffeineCache
Returns the future associated withkey
in this cache, ornull
if there is no cached future forkey
. This method is delegating to theAsyncCache.getIfPresent(Object)
, while recording the cache stats if they are enabled.- Specified by:
getIfPresent
in interfaceCaffeineCache
- Parameters:
key
- key whose associated value is to be returned- Returns:
- the future value to which the specified key is mapped, or
null
if this cache does not contain a mapping for the key - See Also:
AsyncCache.getIfPresent(Object)
-
invalidate
public io.smallrye.mutiny.Uni<Void> invalidate(Object key)
Description copied from interface:Cache
Removes the cache entry identified bykey
from the cache. If the key does not identify any cache entry, nothing will happen.- Specified by:
invalidate
in interfaceCache
- Parameters:
key
- cache key
-
invalidateAll
public io.smallrye.mutiny.Uni<Void> invalidateAll()
Description copied from interface:Cache
Removes all entries from the cache.- Specified by:
invalidateAll
in interfaceCache
-
replaceUniValue
public io.smallrye.mutiny.Uni<Void> replaceUniValue(Object key, Object emittedValue)
Description copied from class:AbstractCache
Replaces the cache value associated with the given key by an item emitted by aUni
. This method can be called several times for the same key, each call will then always replace the existing cache entry with the given emitted value. If the key no longer identifies a cache entry, this method must not put the emitted item into the cache.- Specified by:
replaceUniValue
in classAbstractCache
-
keySet
public Set<Object> keySet()
Description copied from interface:CaffeineCache
Returns an unmodifiableSet
view of the keys contained in this cache. If the cache entries are modified while an iteration over the set is in progress, the set will remain unchanged.- Specified by:
keySet
in interfaceCaffeineCache
- Returns:
- a set view of the keys contained in this cache
-
put
public <V> void put(Object key, CompletableFuture<V> valueFuture)
Description copied from interface:CaffeineCache
Associatesvalue
withkey
in this cache. If the cache previously contained a value associated withkey
, the old value is replaced byvalue
. If the asynchronous computation fails, the entry will be automatically removed.Prefer
Cache.get(Object, Function)
when using the conventional "if cached, return; otherwise create, cache and return" pattern.- Specified by:
put
in interfaceCaffeineCache
- Parameters:
key
- key with which the specified value is to be associatedvalueFuture
- value to be associated with the specified key
-
getCacheInfo
public CaffeineCacheInfo getCacheInfo()
-
getSize
public long getSize()
-
-