Skip to content

Commit 4779323

Browse files
committed
Clarify behaviour of condition attribute of CachePut
Closes gh-26186
1 parent 67112b2 commit 4779323

File tree

1 file changed

+8
-4
lines changed
  • spring-context/src/main/java/org/springframework/cache/annotation

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -31,7 +31,8 @@
3131
*
3232
* <p>In contrast to the {@link Cacheable @Cacheable} annotation, this annotation
3333
* does not cause the advised method to be skipped. Rather, it always causes the
34-
* method to be invoked and its result to be stored in the associated cache. Note
34+
* method to be invoked and its result to be stored in the associated cache if the
35+
* {@link #condition()} and {@link #unless()} expressions match accordingly. Note
3536
* that Java8's {@code Optional} return types are automatically handled and its
3637
* content is stored in the cache if present.
3738
*
@@ -118,10 +119,15 @@
118119
/**
119120
* Spring Expression Language (SpEL) expression used for making the cache
120121
* put operation conditional.
122+
* <p>This expression is evaluated after the method has been called due to the
123+
* nature of the put operation and can therefore refer to the {@code result}.
121124
* <p>Default is {@code ""}, meaning the method result is always cached.
122125
* <p>The SpEL expression evaluates against a dedicated context that provides the
123126
* following meta-data:
124127
* <ul>
128+
* <li>{@code #result} for a reference to the result of the method invocation. For
129+
* supported wrappers such as {@code Optional}, {@code #result} refers to the actual
130+
* object, not the wrapper</li>
125131
* <li>{@code #root.method}, {@code #root.target}, and {@code #root.caches} for
126132
* references to the {@link java.lang.reflect.Method method}, target object, and
127133
* affected cache(s) respectively.</li>
@@ -136,8 +142,6 @@
136142

137143
/**
138144
* Spring Expression Language (SpEL) expression used to veto the cache put operation.
139-
* <p>Unlike {@link #condition}, this expression is evaluated after the method
140-
* has been called and can therefore refer to the {@code result}.
141145
* <p>Default is {@code ""}, meaning that caching is never vetoed.
142146
* <p>The SpEL expression evaluates against a dedicated context that provides the
143147
* following meta-data:

0 commit comments

Comments
 (0)