Skip to content

Commit f749234

Browse files
snicolljhoeller
authored andcommitted
Polish cache javadoc
Issue: SPR-13746 (cherry picked from commit 34b596c)
1 parent e4faaa3 commit f749234

File tree

4 files changed

+205
-75
lines changed

4 files changed

+205
-75
lines changed

spring-context/src/main/java/org/springframework/cache/annotation/CacheEvict.java

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@
2424
import java.lang.annotation.Target;
2525

2626
/**
27-
* Annotation indicating that a method (or all methods on a class) trigger(s)
28-
* a cache invalidate operation.
27+
* Annotation indicating that a method (or all methods on a class) triggers a
28+
* {@link org.springframework.cache.Cache#evict(Object) cache evict} operation.
2929
*
3030
* @author Costin Leau
3131
* @author Stephane Nicoll
@@ -39,57 +39,95 @@
3939
public @interface CacheEvict {
4040

4141
/**
42-
* Qualifier value for the specified cached operation.
43-
* <p>May be used to determine the target cache (or caches), matching the qualifier
44-
* value (or the bean name(s)) of (a) specific bean definition.
42+
* Names of the caches to use for the cache eviction operation.
43+
* <p>Names may be used to determine the target cache (or caches), matching
44+
* the qualifier value or bean name of a specific bean definition.
45+
* @see CacheConfig#cacheNames
4546
*/
4647
String[] value() default {};
4748

4849
/**
49-
* Spring Expression Language (SpEL) attribute for computing the key dynamically.
50-
* <p>Default is "", meaning all method parameters are considered as a key, unless
51-
* a custom {@link #keyGenerator()} has been set.
50+
* Spring Expression Language (SpEL) expression for computing the key dynamically.
51+
* <p>Default is {@code ""}, meaning all method parameters are considered as a key,
52+
* unless a custom {@link #keyGenerator} has been set.
53+
* <p>The SpEL expression evaluates again a dedicated context that provides the
54+
* following meta-data:
55+
* <ul>
56+
* <li>{@code #result} for a reference to the result of the method invocation, which
57+
* can only be used if {@link #beforeInvocation()} is {@code false}.</li>
58+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
59+
* reference to the {@link java.lang.reflect.Method method}, target object and
60+
* affected cache(s) respectively.</li>
61+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
62+
* ({@code #root.targetClass}) are also available.
63+
* <li>Method arguments can be accessed by index. For instance the second argument
64+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
65+
* can also be accessed by name if that information is available.</li>
66+
* </ul>
5267
*/
5368
String key() default "";
5469

5570
/**
56-
* The bean name of the custom {@link org.springframework.cache.interceptor.KeyGenerator} to use.
57-
* <p>Mutually exclusive with the {@link #key()} attribute.
71+
* The bean name of the custom {@link org.springframework.cache.interceptor.KeyGenerator}
72+
* to use.
73+
* <p>Mutually exclusive with the {@link #key} attribute.
74+
* @see CacheConfig#keyGenerator
5875
*/
5976
String keyGenerator() default "";
6077

6178
/**
6279
* The bean name of the custom {@link org.springframework.cache.CacheManager} to use to
6380
* create a default {@link org.springframework.cache.interceptor.CacheResolver} if none
6481
* is set already.
65-
* <p>Mutually exclusive with the {@link #cacheResolver()} attribute.
82+
* <p>Mutually exclusive with the {@link #cacheResolver} attribute.
6683
* @see org.springframework.cache.interceptor.SimpleCacheResolver
84+
* @see CacheConfig#cacheManager
6785
*/
6886
String cacheManager() default "";
6987

7088
/**
71-
* The bean name of the custom {@link org.springframework.cache.interceptor.CacheResolver} to use.
89+
* The bean name of the custom {@link org.springframework.cache.interceptor.CacheResolver}
90+
* to use.
91+
* @see CacheConfig#cacheResolver
7292
*/
7393
String cacheResolver() default "";
7494

7595
/**
76-
* Spring Expression Language (SpEL) attribute used for conditioning the method caching.
77-
* <p>Default is "", meaning the method is always cached.
96+
* Spring Expression Language (SpEL) expression used for making the cache
97+
* eviction operation conditional.
98+
* <p>Default is {@code ""}, meaning the cache eviction is always performed.
99+
* <p>The SpEL expression evaluates again a dedicated context that provides the
100+
* following meta-data:
101+
* <ul>
102+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
103+
* reference to the {@link java.lang.reflect.Method method}, target object and
104+
* affected cache(s) respectively.</li>
105+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
106+
* ({@code #root.targetClass}) are also available.
107+
* <li>Method arguments can be accessed by index. For instance the second argument
108+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
109+
* can also be accessed by name if that information is available.</li>
110+
* </ul>
78111
*/
79112
String condition() default "";
80113

81114
/**
82-
* Whether or not all the entries inside the cache(s) are removed or not. By
83-
* default, only the value under the associated key is removed.
84-
* <p>Note that setting this parameter to {@code true} and specifying a {@link #key()}
85-
* is not allowed.
115+
* Whether all the entries inside the cache(s) are removed.
116+
* <p>By default, only the value under the associated key is removed.
117+
* <p>Note that setting this parameter to {@code true} and specifying a
118+
* {@link #key} is not allowed.
86119
*/
87120
boolean allEntries() default false;
88121

89122
/**
90-
* Whether the eviction should occur after the method is successfully invoked (default)
91-
* or before. The latter causes the eviction to occur irrespective of the method outcome (whether
92-
* it threw an exception or not) while the former does not.
123+
* Whether the eviction should occur before the method is invoked.
124+
* <p>Setting this attribute to {@code true}, causes the eviction to
125+
* occur irrespective of the method outcome (i.e., whether it threw an
126+
* exception or not).
127+
* <p>Defaults to {@code false}, meaning that the cache eviction operation
128+
* will occur <em>after</em> the advised method is invoked successfully (i.e.,
129+
* only if the invocation did not throw an exception).
93130
*/
94131
boolean beforeInvocation() default false;
132+
95133
}
Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,72 +23,118 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26-
import org.springframework.cache.Cache;
27-
2826
/**
29-
* Annotation indicating that a method (or all methods on a class) trigger(s)
30-
* a {@link Cache#put(Object, Object)} operation. As opposed to {@link Cacheable} annotation,
31-
* this annotation does not cause the target method to be skipped - rather it
32-
* always causes the method to be invoked and its result to be placed into the cache.
27+
* Annotation indicating that a method (or all methods on a class) triggers a
28+
* {@link org.springframework.cache.Cache#put(Object, Object) cache put} operation.
29+
*
30+
* <p>In contrast to the {@link Cacheable @Cacheable} annotation, this annotation
31+
* does not cause the advised method to be skipped. Rather, it always causes the
32+
* method to be invoked and its result to be stored in the associated cache.
3333
*
3434
* @author Costin Leau
3535
* @author Phillip Webb
3636
* @author Stephane Nicoll
3737
* @since 3.1
3838
* @see CacheConfig
3939
*/
40-
@Target({ ElementType.METHOD, ElementType.TYPE })
40+
@Target({ElementType.METHOD, ElementType.TYPE})
4141
@Retention(RetentionPolicy.RUNTIME)
4242
@Inherited
4343
@Documented
4444
public @interface CachePut {
4545

4646
/**
47-
* Name of the caches in which the update takes place.
48-
* <p>May be used to determine the target cache (or caches), matching the
49-
* qualifier value (or the bean name(s)) of (a) specific bean definition.
47+
* Names of the caches to use for the cache put operation.
48+
* <p>Names may be used to determine the target cache (or caches), matching
49+
* the qualifier value or bean name of a specific bean definition.
50+
* @see CacheConfig#cacheNames
5051
*/
5152
String[] value() default {};
5253

5354
/**
54-
* Spring Expression Language (SpEL) attribute for computing the key dynamically.
55-
* <p>Default is "", meaning all method parameters are considered as a key, unless
56-
* a custom {@link #keyGenerator()} has been set.
55+
* Spring Expression Language (SpEL) expression for computing the key dynamically.
56+
* <p>Default is {@code ""}, meaning all method parameters are considered as a key,
57+
* unless a custom {@link #keyGenerator} has been set.
58+
* <p>The SpEL expression evaluates again a dedicated context that provides the
59+
* following meta-data:
60+
* <ul>
61+
* <li>{@code #result} for a reference to the result of the method invocation.</li>
62+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
63+
* reference to the {@link java.lang.reflect.Method method}, target object and
64+
* affected cache(s) respectively.</li>
65+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
66+
* ({@code #root.targetClass}) are also available.
67+
* <li>Method arguments can be accessed by index. For instance the second argument
68+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
69+
* can also be accessed by name if that information is available.</li>
70+
* </ul>
5771
*/
5872
String key() default "";
5973

6074
/**
61-
* The bean name of the custom {@link org.springframework.cache.interceptor.KeyGenerator} to use.
62-
* <p>Mutually exclusive with the {@link #key()} attribute.
75+
* The bean name of the custom {@link org.springframework.cache.interceptor.KeyGenerator}
76+
* to use.
77+
* <p>Mutually exclusive with the {@link #key} attribute.
78+
* @see CacheConfig#keyGenerator
6379
*/
6480
String keyGenerator() default "";
6581

6682
/**
6783
* The bean name of the custom {@link org.springframework.cache.CacheManager} to use to
6884
* create a default {@link org.springframework.cache.interceptor.CacheResolver} if none
6985
* is set already.
70-
* <p>Mutually exclusive with the {@link #cacheResolver()} attribute.
86+
* <p>Mutually exclusive with the {@link #cacheResolver} attribute.
7187
* @see org.springframework.cache.interceptor.SimpleCacheResolver
88+
* @see CacheConfig#cacheManager
7289
*/
7390
String cacheManager() default "";
7491

7592
/**
76-
* The bean name of the custom {@link org.springframework.cache.interceptor.CacheResolver} to use.
93+
* The bean name of the custom {@link org.springframework.cache.interceptor.CacheResolver}
94+
* to use.
95+
* @see CacheConfig#cacheResolver
7796
*/
7897
String cacheResolver() default "";
7998

8099
/**
81-
* Spring Expression Language (SpEL) attribute used for conditioning the cache update.
82-
* <p>Default is "", meaning the method result is always cached.
100+
* Spring Expression Language (SpEL) expression used for making the cache
101+
* put operation conditional.
102+
* <p>Default is {@code ""}, meaning the method result is always cached.
103+
* <p>The SpEL expression evaluates again a dedicated context that provides the
104+
* following meta-data:
105+
* <ul>
106+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
107+
* reference to the {@link java.lang.reflect.Method method}, target object and
108+
* affected cache(s) respectively.</li>
109+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
110+
* ({@code #root.targetClass}) are also available.
111+
* <li>Method arguments can be accessed by index. For instance the second argument
112+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
113+
* can also be accessed by name if that information is available.</li>
114+
* </ul>
83115
*/
84116
String condition() default "";
85117

86118
/**
87-
* Spring Expression Language (SpEL) attribute used to veto the cache update.
88-
* <p>Unlike {@link #condition()}, this expression is evaluated after the method
89-
* has been called and can therefore refer to the {@code result}. Default is "",
90-
* meaning that caching is never vetoed.
119+
* Spring Expression Language (SpEL) expression used to veto the cache put operation.
120+
* <p>Unlike {@link #condition}, this expression is evaluated after the method
121+
* has been called and can therefore refer to the {@code result}.
122+
* <p>Default is {@code ""}, meaning that caching is never vetoed.
123+
* <p>The SpEL expression evaluates again a dedicated context that provides the
124+
* following meta-data:
125+
* <ul>
126+
* <li>{@code #result} for a reference to the result of the method invocation.</li>
127+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
128+
* reference to the {@link java.lang.reflect.Method method}, target object and
129+
* affected cache(s) respectively.</li>
130+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
131+
* ({@code #root.targetClass}) are also available.
132+
* <li>Method arguments can be accessed by index. For instance the second argument
133+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
134+
* can also be accessed by name if that information is available.</li>
135+
* </ul>
91136
* @since 3.2
92137
*/
93138
String unless() default "";
139+
94140
}

0 commit comments

Comments
 (0)