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) {
             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:
    CacheManager
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String value
      The name of the cache.
    • Element Detail

      • value

        String value
        The name of the cache.