From 806c83591c694c95ecd605261aa1f3e349fd12cd Mon Sep 17 00:00:00 2001 From: liguoxiong Date: Tue, 9 Apr 2019 03:27:42 +0800 Subject: [PATCH 1/2] Evaluate key only if necessary Prior to this commit a @CachePut operation would fail if the key expression is invalid, but guarded with an unless condition as the former was evaluated too early. This commit makes sure that key for a put is only evaluated if the put operation is active. Note that this does not apply for @Cacheable as the key needs to be computed early to determine if a matching entry exists in the cache. See gh-22769 --- .../cache/annotation/CacheEvict.java | 4 ++ .../cache/annotation/Cacheable.java | 3 ++ .../cache/interceptor/CacheAspectSupport.java | 22 ++++----- .../cache/AbstractCacheAnnotationTests.java | 48 ++++++++++++++++++- .../beans/AnnotatedClassCacheableService.java | 13 ++++- .../cache/beans/CacheableService.java | 6 ++- .../cache/beans/DefaultCacheableService.java | 13 ++++- 7 files changed, 93 insertions(+), 16 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CacheEvict.java b/spring-context/src/main/java/org/springframework/cache/annotation/CacheEvict.java index 43f095236a..5fb2f90289 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CacheEvict.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CacheEvict.java @@ -119,6 +119,10 @@ public @interface CacheEvict { *

The SpEL expression evaluates against a dedicated context that provides the * following meta-data: *