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

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,12 @@
package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;
import org.springframework.core.testfixture.io.SerializationTestUtils;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb
* @author Stephane Nicoll
* @author Juergen Hoeller
* @author Sebastien Deleuze
*/
public class SimpleKeyGeneratorTests {
@@ -126,7 +130,8 @@ public class SimpleKeyGeneratorTests {
private Object generateKey(Object[] arguments) {
return this.generator.generate(null, null, arguments);
Method method = ReflectionUtils.findMethod(this.getClass(), "generateKey", Object[].class);
return this.generator.generate(this, method, arguments);
}
}