Package io.quarkus.cache
Interface Cache
-
- All Known Subinterfaces:
CaffeineCache
- All Known Implementing Classes:
AbstractCache
,CaffeineCacheImpl
,NoOpCache
public interface Cache
Use this interface to interact with a cache programmatically e.g. store, retrieve or delete cache values. The cache can be injected using theCacheName
annotation or retrieved usingCacheManager.getCache(String)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends Cache>
Tas(Class<T> type)
Returns this cache as an instance of the provided type if possible.<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.Object
getDefaultKey()
Returns the unique and immutable default key for the current cache.String
getName()
Returns the cache name.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.
-
-
-
Method Detail
-
getName
String getName()
Returns the cache name.- Returns:
- cache name
-
getDefaultKey
Object getDefaultKey()
Returns the unique and immutable default key for the current cache. This key is used by the annotations caching API when a no-args method annotated withCacheResult
orCacheInvalidate
is invoked. It can also be used with the programmatic caching API.- Returns:
- default cache key
-
get
<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.- Type Parameters:
K
- cache key typeV
- cache value type- Parameters:
key
- cache keyvalueLoader
- function used to compute a cache value ifkey
is not already associated with a value- Returns:
- a lazy asynchronous action that will emit a cache value
- Throws:
NullPointerException
- if the key isnull
CacheException
- if an exception is thrown during a cache value computation
-
invalidate
io.smallrye.mutiny.Uni<Void> invalidate(Object key)
Removes the cache entry identified bykey
from the cache. If the key does not identify any cache entry, nothing will happen.- Parameters:
key
- cache key- Throws:
NullPointerException
- if the key isnull
-
invalidateAll
io.smallrye.mutiny.Uni<Void> invalidateAll()
Removes all entries from the cache.
-
as
<T extends Cache> T as(Class<T> type)
Returns this cache as an instance of the provided type if possible.- Returns:
- cache instance of the provided type
- Throws:
IllegalStateException
- if this cache is not an instance oftype
-
-