All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.cache.CacheName Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.cache;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import jakarta.enterprise.util.Nonbinding;
import jakarta.inject.Qualifier;

/**
 * 

* Use this annotation on a field, a constructor parameter or a method parameter to inject a {@link Cache} and interact with it * programmatically e.g. store, retrieve or delete cache values. *

*

* Field injection example: * *

 * {@literal @}ApplicationScoped
 * public class CachedService {
 *
 *     {@literal @}CacheName("my-cache")
 *     Cache cache;
 *
 *     String getExpensiveValue(Object key) {
 *         {@code Uni} cacheValue = cache.get(key, () -> expensiveService.getValue(key));
 *         return cacheValue.await().indefinitely();
 *     }
 * }
 * 
* * Constructor parameter injection example: * *
 * {@literal @}ApplicationScoped
 * public class CachedService {
 *
 *     private Cache cache;
 *
 *     public CachedService(@CacheName("my-cache") Cache cache) {
 *         this.cache = cache;
 *     }
 *
 *     String getExpensiveValue(Object key) {
 *         {@code Uni} cacheValue = cache.get(key, () -> expensiveService.getValue(key));
 *         return cacheValue.await().indefinitely();
 *     }
 * }
 * 
* * Method parameter injection example: * *
 * {@literal @}ApplicationScoped
 * public class CachedService {
 *
 *     private Cache cache;
 *
 *     {@literal @}Inject
 *     public void setCache(@CacheName("my-cache") Cache cache) {
 *         this.cache = cache;
 *     }
 *
 *     String getExpensiveValue(Object key) {
 *         {@code Uni} cacheValue = cache.get(key, () -> expensiveService.getValue(key));
 *         return cacheValue.await().indefinitely();
 *     }
 * }
 * 
*

* * @see CacheManager */ @Qualifier @Target({ FIELD, METHOD, PARAMETER }) @Retention(RUNTIME) public @interface CacheName { /** * The name of the cache. */ @Nonbinding String value(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy