Skip to content

Commit 624d6dd

Browse files
committed
Expose actual result value for @CacheEvict condition
Closes gh-32960
1 parent 0ea96b4 commit 624d6dd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ private Object processCacheEvicts(Collection<CacheOperationContext> contexts, bo
630630
if (result instanceof CompletableFuture<?> future) {
631631
return future.whenComplete((value, ex) -> {
632632
if (ex == null) {
633-
performCacheEvicts(applicable, result);
633+
performCacheEvicts(applicable, value);
634634
}
635635
});
636636
}
@@ -1112,7 +1112,7 @@ public Object processCacheEvicts(List<CacheOperationContext> contexts, @Nullable
11121112
ReactiveAdapter adapter = (result != null ? this.registry.getAdapter(result.getClass()) : null);
11131113
if (adapter != null) {
11141114
return adapter.fromPublisher(Mono.from(adapter.toPublisher(result))
1115-
.doOnSuccess(value -> performCacheEvicts(contexts, result)));
1115+
.doOnSuccess(value -> performCacheEvicts(contexts, value)));
11161116
}
11171117
return NOT_HANDLED;
11181118
}

spring-context/src/test/java/org/springframework/cache/CacheReproTests.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -606,9 +606,9 @@ public CompletableFuture<TestBean> insertItem(TestBean item) {
606606
return CompletableFuture.completedFuture(item);
607607
}
608608

609-
@CacheEvict(cacheNames = "itemCache", allEntries = true)
610-
public CompletableFuture<Void> clear() {
611-
return CompletableFuture.completedFuture(null);
609+
@CacheEvict(cacheNames = "itemCache", allEntries = true, condition = "#result > 0")
610+
public CompletableFuture<Integer> clear() {
611+
return CompletableFuture.completedFuture(1);
612612
}
613613
}
614614

@@ -655,9 +655,9 @@ public Mono<TestBean> insertItem(TestBean item) {
655655
return Mono.just(item);
656656
}
657657

658-
@CacheEvict(cacheNames = "itemCache", allEntries = true)
659-
public Mono<Void> clear() {
660-
return Mono.empty();
658+
@CacheEvict(cacheNames = "itemCache", allEntries = true, condition = "#result > 0")
659+
public Mono<Integer> clear() {
660+
return Mono.just(1);
661661
}
662662
}
663663

@@ -706,9 +706,9 @@ public Flux<TestBean> insertItem(String id, List<TestBean> item) {
706706
return Flux.fromIterable(item);
707707
}
708708

709-
@CacheEvict(cacheNames = "itemCache", allEntries = true)
710-
public Flux<Void> clear() {
711-
return Flux.empty();
709+
@CacheEvict(cacheNames = "itemCache", allEntries = true, condition = "#result > 0")
710+
public Flux<Integer> clear() {
711+
return Flux.just(1);
712712
}
713713
}
714714

0 commit comments

Comments
 (0)