Package io.quarkus.cache
Annotation 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) {
Uni<String>
cacheValue = cache.get(key, () -> expensiveService.getValue(key));
return cacheValue.await().indefinitely();
}
}
Constructor parameter injection example:
@ApplicationScoped
public class CachedService {
private Cache cache;
public CachedService(@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();
}
}
Method parameter injection example:
@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:
-
Required Element Summary
-
Element Details
-
value
String valueThe name of the cache.
-