Add Coroutines support for @Cacheable

This commit adds Coroutines support for `@Cacheable`.

It also refines SimpleKeyGenerator to ignore Continuation
parameters (Kotlin does not allow to have the same method
signature with both suspending and non-suspending variants)
and refines
org.springframework.aop.framework.CoroutinesUtils.awaitSingleOrNull
in order to wrap plain value to Mono.

Closes gh-31412
This commit is contained in:
Sébastien Deleuze
2023-10-15 19:11:13 +02:00
parent 39a282e463
commit 466c8d8f23
9 changed files with 270 additions and 9 deletions

View File

@@ -36,10 +36,11 @@ abstract class CoroutinesUtils {
return ReactiveFlowKt.asFlow((Publisher<?>) publisher);
}
@SuppressWarnings("unchecked")
@Nullable
static Object awaitSingleOrNull(Object mono, Object continuation) {
return MonoKt.awaitSingleOrNull((Mono<?>) mono, (Continuation<Object>) continuation);
@SuppressWarnings({"unchecked", "rawtypes"})
static Object awaitSingleOrNull(Object value, Object continuation) {
return MonoKt.awaitSingleOrNull(value instanceof Mono mono ? mono : Mono.just(value),
(Continuation<Object>) continuation);
}
}