diff --git a/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc b/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc index eea2a0a7744..276dd91e5c2 100644 --- a/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc +++ b/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc @@ -381,10 +381,12 @@ available to the context so that you can use them for key and conditional comput | `result` | Evaluation context -| The result of the method call (the value to be cached). Only available in `unless` - expressions, `cache put` expressions (to compute the `key`), or `cache evict` - expressions (when `beforeInvocation` is `false`). For supported wrappers (such as - `Optional`), `#result` refers to the actual object, not the wrapper. +| The result of the method call (the value to be cached, or evaluated for eviction). Only + available in `unless` expressions, `cache put` expressions (`key`, `condition`, or + `unless`), or `cache evict` expressions (`key` or `condition`, when `beforeInvocation` + is `false`). For supported wrappers (such as `Optional`), `#result` refers to the + actual object, not the wrapper. For a method returning a `Flux`, `#result` refers to a + `List` containing all values collected from the `Flux`. | `#result` |=== @@ -464,7 +466,12 @@ not the case with `@Cacheable` which adds data to the cache or updates data in t and, thus, requires a result. As of 6.1, `@CacheEvict` takes `CompletableFuture` and reactive return types into account, -performing an after-invocation evict operation whenever processing has completed. +performing an after-invocation evict operation whenever processing has completed. As with +`@Cacheable` and `@CachePut`, for a method returning a `Flux`, all emitted elements are +collected into a `List` before the evict operation is performed. When `beforeInvocation` +is `false`, that same `List` is what the `condition` SpEL expression sees as the +`#result`. Either way, the `Flux` returned to the caller is unaffected by this collection +process. TIP: When `@CacheEvict` is combined with `@Retryable`, the retry advice is applied outermost, so eviction runs again on every retry attempt -- and, with 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 a85b2fef2bf..00841d7a14a 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 @@ -77,7 +77,8 @@ public @interface CacheEvict { *
  • {@code #result} for a reference to the result of the method invocation, which * can only be used if {@link #beforeInvocation()} is {@code false}. For supported * wrappers such as {@code Optional}, {@code #result} refers to the actual object, - * not the wrapper
  • + * not the wrapper. For a method that returns a {@code Flux}, {@code #result} refers + * to a {@code List} containing all values collected from the {@code Flux}. *
  • {@code #root.method}, {@code #root.target}, and {@code #root.caches} for * references to the {@link java.lang.reflect.Method method}, target object, and * affected cache(s) respectively.
  • @@ -123,6 +124,11 @@ public @interface CacheEvict { *

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