Package io.quarkus.cache
Annotation Type CacheName
-
@Qualifier @Target({FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) public @interface CacheName
Use this annotation on a field, a constructor parameter or a method parameter to inject a
Cache
and interact with it programmatically e.g. store, retrieve or delete cache values.Field injection example:
@ApplicationScoped public class CachedService { @CacheName("my-cache") Cache cache; String getExpensiveValue(Object key) {
Constructor parameter injection example:Uni<String>
cacheValue = cache.get(key, () -> expensiveService.getValue(key)); return cacheValue.await().indefinitely(); } }@ApplicationScoped public class CachedService { private Cache cache; public CachedService(@CacheName("my-cache") Cache cache) { this.cache = cache; } String getExpensiveValue(Object key) {
Method parameter injection example:Uni<String>
cacheValue = cache.get(key, () -> expensiveService.getValue(key)); return cacheValue.await().indefinitely(); } }@ApplicationScoped public class CachedService { private Cache cache; @Inject public void setCache(@CacheName("my-cache") Cache cache) { this.cache = cache; } String getExpensiveValue(Object key) {
Uni<String>
cacheValue = cache.get(key, () -> expensiveService.getValue(key)); return cacheValue.await().indefinitely(); } }- See Also:
CacheManager
-
-
Element Detail
-
value
String value
The name of the cache.
-
-