Package io.micronaut.cache.annotation
Annotation Interface Cacheable
@Target({METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Documented
@CacheConfig
@CacheAnnotation
public @interface Cacheable
An annotation that can be applied at the type or method level to indicate that the return value of the method
should be cached for
the configured cacheNames()
.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionboolean
Whether an atomic operation should be attempted to retrieve the cache value.String[]
Alias forCacheConfig.cacheNames()
.Evaluated expression that can be used to indicate whether the value should be cached.Class<? extends CacheKeyGenerator>
Alias forCacheConfig.keyGenerator()
.String[]
Limit the automaticCacheKeyGenerator
to the given parameter names.String[]
Alias forCacheConfig.cacheNames()
.
-
Element Details
-
value
@AliasFor(member="cacheNames") @AliasFor(annotation=CacheConfig.class,member="cacheNames") String[] valueAlias forCacheConfig.cacheNames()
.- Returns:
- The cache names
- Default:
- {}
-
cacheNames
Alias forCacheConfig.cacheNames()
.- Returns:
- The cache names
- Default:
- {}
-
parameters
String[] parametersLimit the automaticCacheKeyGenerator
to the given parameter names. Mutually exclusive withkeyGenerator()
- Returns:
- The parameter names that make up the key.
- Default:
- {}
-
keyGenerator
@AliasFor(annotation=CacheConfig.class, member="keyGenerator") @InstantiatedMember Class<? extends CacheKeyGenerator> keyGeneratorAlias forCacheConfig.keyGenerator()
.- Returns:
- The cache key generator class
- Default:
- io.micronaut.cache.interceptor.DefaultCacheKeyGenerator.class
-
atomic
boolean atomicWhether an atomic operation should be attempted to retrieve the cache value. This will call
SyncCache.get(Object, Class, java.util.function.Supplier)
if set totrue
otherwiseSyncCache.get(Object, Class)
will be called which is non-atomicNote that atomic operations will pick the first cache name specified and ignore the remaining.
- Returns:
- True if an atomic operation should be attempted
- Default:
- false
-
condition
String conditionEvaluated expression that can be used to indicate whether the value should be cached. Will be evaluated each time the method is called, and if the condition evaluates to false the cache will not be used.- Returns:
- The condition
- Since:
- 4.2.0
- See Also:
- Default:
- ""
-