Skip to content

Commit 34b596c

Browse files
committed
Polish cache javadoc
Issue: SPR-13746
1 parent 0d6545f commit 34b596c

File tree

5 files changed

+105
-4
lines changed

5 files changed

+105
-4
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@
6262
* Spring Expression Language (SpEL) expression for computing the key dynamically.
6363
* <p>Default is {@code ""}, meaning all method parameters are considered as a key, unless
6464
* a custom {@link #keyGenerator} has been set.
65+
* <p>The SpEL expression evaluates again a dedicated context that provides the
66+
* following meta-data:
67+
* <ul>
68+
* <li>{@code #result} for a reference to the result of the method invocation, which
69+
* can only be used if {@link #beforeInvocation()} is {@code false}.</li>
70+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
71+
* reference to the {@link java.lang.reflect.Method method}, target object and
72+
* affected cache(s) respectively.</li>
73+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
74+
* ({@code #root.targetClass}) are also available.
75+
* <li>Method arguments can be accessed by index. For instance the second argument
76+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
77+
* can also be accessed by name if that information is available.</li>
78+
* </ul>
6579
*/
6680
String key() default "";
6781

@@ -92,6 +106,18 @@
92106
* Spring Expression Language (SpEL) expression used for making the cache
93107
* eviction operation conditional.
94108
* <p>Default is {@code ""}, meaning the cache eviction is always performed.
109+
* <p>The SpEL expression evaluates again a dedicated context that provides the
110+
* following meta-data:
111+
* <ul>
112+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
113+
* reference to the {@link java.lang.reflect.Method method}, target object and
114+
* affected cache(s) respectively.</li>
115+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
116+
* ({@code #root.targetClass}) are also available.
117+
* <li>Method arguments can be accessed by index. For instance the second argument
118+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
119+
* can also be accessed by name if that information is available.</li>
120+
* </ul>
95121
*/
96122
String condition() default "";
97123

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@
6868
* Spring Expression Language (SpEL) expression for computing the key dynamically.
6969
* <p>Default is {@code ""}, meaning all method parameters are considered as a key, unless
7070
* a custom {@link #keyGenerator} has been set.
71+
* <p>The SpEL expression evaluates again a dedicated context that provides the
72+
* following meta-data:
73+
* <ul>
74+
* <li>{@code #result} for a reference to the result of the method invocation.</li>
75+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
76+
* reference to the {@link java.lang.reflect.Method method}, target object and
77+
* affected cache(s) respectively.</li>
78+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
79+
* ({@code #root.targetClass}) are also available.
80+
* <li>Method arguments can be accessed by index. For instance the second argument
81+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
82+
* can also be accessed by name if that information is available.</li>
83+
* </ul>
7184
*/
7285
String key() default "";
7386

@@ -98,6 +111,18 @@
98111
* Spring Expression Language (SpEL) expression used for making the cache
99112
* put operation conditional.
100113
* <p>Default is {@code ""}, meaning the method result is always cached.
114+
* <p>The SpEL expression evaluates again a dedicated context that provides the
115+
* following meta-data:
116+
* <ul>
117+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
118+
* reference to the {@link java.lang.reflect.Method method}, target object and
119+
* affected cache(s) respectively.</li>
120+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
121+
* ({@code #root.targetClass}) are also available.
122+
* <li>Method arguments can be accessed by index. For instance the second argument
123+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
124+
* can also be accessed by name if that information is available.</li>
125+
* </ul>
101126
*/
102127
String condition() default "";
103128

@@ -106,6 +131,19 @@
106131
* <p>Unlike {@link #condition}, this expression is evaluated after the method
107132
* has been called and can therefore refer to the {@code result}.
108133
* <p>Default is {@code ""}, meaning that caching is never vetoed.
134+
* <p>The SpEL expression evaluates again a dedicated context that provides the
135+
* following meta-data:
136+
* <ul>
137+
* <li>{@code #result} for a reference to the result of the method invocation.</li>
138+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
139+
* reference to the {@link java.lang.reflect.Method method}, target object and
140+
* affected cache(s) respectively.</li>
141+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
142+
* ({@code #root.targetClass}) are also available.
143+
* <li>Method arguments can be accessed by index. For instance the second argument
144+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
145+
* can also be accessed by name if that information is available.</li>
146+
* </ul>
109147
* @since 3.2
110148
*/
111149
String unless() default "";

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@
7373
* Spring Expression Language (SpEL) expression for computing the key dynamically.
7474
* <p>Default is {@code ""}, meaning all method parameters are considered as a key,
7575
* unless a custom {@link #keyGenerator} has been configured.
76+
* <p>The SpEL expression evaluates again a dedicated context that provides the
77+
* following meta-data:
78+
* <ul>
79+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
80+
* reference to the {@link java.lang.reflect.Method method}, target object and
81+
* affected cache(s) respectively.</li>
82+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
83+
* ({@code #root.targetClass}) are also available.
84+
* <li>Method arguments can be accessed by index. For instance the second argument
85+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
86+
* can also be accessed by name if that information is available.</li>
87+
* </ul>
7688
*/
7789
String key() default "";
7890

@@ -103,6 +115,18 @@
103115
* Spring Expression Language (SpEL) expression used for making the method
104116
* caching conditional.
105117
* <p>Default is {@code ""}, meaning the method result is always cached.
118+
* <p>The SpEL expression evaluates again a dedicated context that provides the
119+
* following meta-data:
120+
* <ul>
121+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
122+
* reference to the {@link java.lang.reflect.Method method}, target object and
123+
* affected cache(s) respectively.</li>
124+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
125+
* ({@code #root.targetClass}) are also available.
126+
* <li>Method arguments can be accessed by index. For instance the second argument
127+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
128+
* can also be accessed by name if that information is available.</li>
129+
* </ul>
106130
*/
107131
String condition() default "";
108132

@@ -111,6 +135,19 @@
111135
* <p>Unlike {@link #condition}, this expression is evaluated after the method
112136
* has been called and can therefore refer to the {@code result}.
113137
* <p>Default is {@code ""}, meaning that caching is never vetoed.
138+
* <p>The SpEL expression evaluates again a dedicated context that provides the
139+
* following meta-data:
140+
* <ul>
141+
* <li>{@code #result} for a reference to the result of the method invocation.</li>
142+
* <li>{@code #root.method}, {@code #root.target} and {@code #root.caches} for a
143+
* reference to the {@link java.lang.reflect.Method method}, target object and
144+
* affected cache(s) respectively.</li>
145+
* <li>Shortcuts for the method name ({@code #root.methodName}) and target class
146+
* ({@code #root.targetClass}) are also available.
147+
* <li>Method arguments can be accessed by index. For instance the second argument
148+
* can be access via {@code #root.args[1]}, {@code #p1} or {@code #a1}. Arguments
149+
* can also be accessed by name if that information is available.</li>
150+
* </ul>
114151
* @since 3.2
115152
*/
116153
String unless() default "";

src/asciidoc/core-beans.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8139,9 +8139,9 @@ available to the context so one can use them for conditional event processing:
81398139
| __argument name__
81408140
| evaluation context
81418141
| Name of any of the method argument. If for some reason the names are not available
8142-
(ex: no debug information), the argument names are also available under the `a<#arg>`
8142+
(ex: no debug information), the argument names are also available under the `#a<#arg>`
81438143
where __#arg__ stands for the argument index (starting from 0).
8144-
| `iban` or `a0` (one can also use `p0` or `p<#arg>` notation as an alias).
8144+
| `#iban` or `#a0` (one can also use `#p0` or `#p<#arg>` notation as an alias).
81458145
|===
81468146

81478147
Note that `#root.event` allows you to access to the underlying event, even if your method

src/asciidoc/integration.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8463,9 +8463,9 @@ conditional computations:
84638463
| __argument name__
84648464
| evaluation context
84658465
| Name of any of the method argument. If for some reason the names are not available
8466-
(ex: no debug information), the argument names are also available under the `a<#arg>`
8466+
(ex: no debug information), the argument names are also available under the `#a<#arg>`
84678467
where __#arg__ stands for the argument index (starting from 0).
8468-
| `iban` or `a0` (one can also use `p0` or `p<#arg>` notation as an alias).
8468+
| `#iban` or `#a0` (one can also use `#p0` or `#p<#arg>` notation as an alias).
84698469

84708470
| result
84718471
| evaluation context

0 commit comments

Comments
 (0)