Package io.quarkus.cache
Interface Cache
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 the
@io.quarkus.cache.CacheName annotation or retrieved using CacheManager.getCache(String).-
Method Summary
Modifier and TypeMethodDescription<T extends Cache>
TReturns this cache as an instance of the provided type if possible.<K,V> io.smallrye.mutiny.Uni<V> Returns a lazy asynchronous action that will emit the cache value identified bykey, obtaining that value fromvalueLoaderif necessary.<K,V> io.smallrye.mutiny.Uni<V> Returns a lazy asynchronous action that will emit the cache value identified bykey, obtaining that value fromvalueLoaderif necessary.Returns the unique and immutable default key for the current cache.getName()Returns the cache name.io.smallrye.mutiny.Uni<Void>invalidate(Object key) Removes the cache entry identified bykeyfrom the cache.io.smallrye.mutiny.Uni<Void>Removes all entries from the cache.io.smallrye.mutiny.Uni<Void>invalidateIf(Predicate<Object> predicate) Removes all cache entries whose keys match the given predicate.
-
Method Details
-
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 with@io.quarkus.cache.CacheResultor@io.quarkus.cache.CacheInvalidateis invoked. It can also be used with the programmatic caching API.- Returns:
- default cache key
-
get
Returns a lazy asynchronous action that will emit the cache value identified bykey, obtaining that value fromvalueLoaderif necessary.- Type Parameters:
K- cache key typeV- cache value type- Parameters:
key- cache keyvalueLoader- function used to compute a cache value ifkeyis not already associated with a value- Returns:
- a lazy asynchronous action that will emit a cache value
- Throws:
NullPointerException- if the key isnullCacheException- if an exception is thrown during a cache value computation
-
getAsync
Returns a lazy asynchronous action that will emit the cache value identified bykey, obtaining that value fromvalueLoaderif necessary.- Type Parameters:
K-V-- Parameters:
key-valueLoader-- Returns:
- a lazy asynchronous action that will emit a cache value
- Throws:
NullPointerException- if the key isnull
-
invalidate
Removes the cache entry identified bykeyfrom 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. -
invalidateIf
Removes all cache entries whose keys match the given predicate.- Parameters:
predicate-
-
as
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
-