Annotation Type TTLCachePut
-
@Target({TYPE,METHOD}) @Retention(RUNTIME) @Inherited @Documented @CachePut(cacheResolver="ttlCacheResolver") public @interface TTLCachePutA variant ofCachePutthat supports time-to-live (TTL) settings for cache entries.This annotation can be used on types and methods to indicate that the result of invoking a method should be cached with a specific time-to-live duration. Unlike the standard
CachePut, this annotation allows specifying an expiration time after which the cached value will be automatically invalidated.Example Usage
{@code- Since:
- 1.0.0
- Author:
- Mercy
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description longexpireThe expire time for cacheable entry
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.String[]cacheManagersThe bean names of the customCacheManagerjava.lang.String[]cacheNamesNames of the caches in which method invocation results are stored.java.lang.StringconditionSpring Expression Language (SpEL) expression used for making the method caching conditional.java.lang.StringkeySpring Expression Language (SpEL) expression for computing the key dynamically.java.lang.StringkeyGeneratorThe bean name of the customKeyGeneratorto use.java.util.concurrent.TimeUnittimeUnitThetimeunitof expirejava.lang.StringunlessSpring Expression Language (SpEL) expression used to veto method caching.java.lang.String[]valueAlias forcacheNames().
-
-
-
-
value
@AliasFor(annotation=org.springframework.cache.annotation.CachePut.class) java.lang.String[] value
Alias forcacheNames().- Default:
- {}
-
-
-
cacheNames
@AliasFor(annotation=org.springframework.cache.annotation.CachePut.class) java.lang.String[] cacheNames
Names of the caches in which method invocation results are stored.Names may be used to determine the target cache (or caches), matching the qualifier value or bean name of a specific bean definition.
- Since:
- 4.2
- See Also:
value(),CacheConfig.cacheNames()
- Default:
- {}
-
-
-
key
@AliasFor(annotation=org.springframework.cache.annotation.CachePut.class) java.lang.String key
Spring Expression Language (SpEL) expression for computing the key dynamically.Default is
"", meaning all method parameters are considered as a key, unless a customkeyGenerator()has been configured.The SpEL expression evaluates against a dedicated context that provides the following meta-data:
#root.method,#root.target, and#root.cachesfor references to themethod, target object, and affected cache(s) respectively.- Shortcuts for the method name (
#root.methodName) and target class (#root.targetClass) are also available. - Method arguments can be accessed by index. For instance the second argument
can be accessed via
#root.args[1],#p1or#a1. Arguments can also be accessed by name if that information is available.
- Default:
- ""
-
-
-
keyGenerator
@AliasFor(annotation=org.springframework.cache.annotation.CachePut.class) java.lang.String keyGenerator
The bean name of the customKeyGeneratorto use.Mutually exclusive with the
key()attribute.- See Also:
CacheConfig.keyGenerator()
- Default:
- ""
-
-
-
condition
@AliasFor(annotation=org.springframework.cache.annotation.CachePut.class) java.lang.String condition
Spring Expression Language (SpEL) expression used for making the method caching conditional. Cache the result if the condition evaluates totrue.Default is
"", meaning the method result is always cached.The SpEL expression evaluates against a dedicated context that provides the following meta-data:
#root.method,#root.target, and#root.cachesfor references to themethod, target object, and affected cache(s) respectively.- Shortcuts for the method name (
#root.methodName) and target class (#root.targetClass) are also available. - Method arguments can be accessed by index. For instance the second argument
can be accessed via
#root.args[1],#p1or#a1. Arguments can also be accessed by name if that information is available.
- Default:
- ""
-
-
-
unless
@AliasFor(annotation=org.springframework.cache.annotation.CachePut.class) java.lang.String unless
Spring Expression Language (SpEL) expression used to veto method caching. Veto caching the result if the condition evaluates totrue.Unlike
condition(), this expression is evaluated after the method has been called and can therefore refer to theresult.Default is
"", meaning that caching is never vetoed.The SpEL expression evaluates against a dedicated context that provides the following meta-data:
#resultfor a reference to the result of the method invocation. For supported wrappers such asOptional,#resultrefers to the actual object, not the wrapper#root.method,#root.target, and#root.cachesfor references to themethod, target object, and affected cache(s) respectively.- Shortcuts for the method name (
#root.methodName) and target class (#root.targetClass) are also available. - Method arguments can be accessed by index. For instance the second argument
can be accessed via
#root.args[1],#p1or#a1. Arguments can also be accessed by name if that information is available.
- Since:
- 3.2
- Default:
- ""
-
-