Package io.quarkus.cache
Interface Cache
-
- All Known Subinterfaces:
CaffeineCache
- All Known Implementing Classes:
AbstractCache,CaffeineCacheImpl,NoOpCache
public interface CacheUse this interface to interact with a cache programmatically e.g. store, retrieve or delete cache values. The cache can be injected using theCacheNameannotation 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 fromvalueLoaderif necessary.ObjectgetDefaultKey()Returns the unique and immutable default key for the current cache.StringgetName()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>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 withCacheResultorCacheInvalidateis 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 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
-
invalidate
io.smallrye.mutiny.Uni<Void> invalidate(Object key)
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.
-
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
-
-