In springboot-webflux:3.2.0. is there any support for reactive caching in cacahe lib for example:
import org.springframework.cache.interceptor.ReactiveCacheKeyGenerator; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono;
import java.lang.reflect.Method;
@Component("customReactiveKeyGenerator") public class CustomReactiveKeyGenerator implements ReactiveCacheKeyGenerator {
@Override
public Mono<Object> generate(String cacheName, Object target, Method method, Object... params) {
return ReactiveSecurityContextHolder.getContext()
.map(securityContext -> {
// Extract relevant information, such as the username
String username = securityContext.getAuthentication().getName();
// Create a key based on the method name and username
StringBuilder key = new StringBuilder();
key.append(method.getName());
key.append(":").append(username);
// You can also include additional parameters in the key
for (Object param : params) {
if (param instanceof String) {
key.append(":").append(param);
}
}
return key.toString();
});
}
}
Comment From: jhoeller
This is a duplicate of #31973 which we recently declined since it is currently not supported by design: https://github.com/spring-projects/spring-framework/issues/31973#issuecomment-1880722965
If we can find an arrangement where we are able to support a Mono
type coming out of a custom KeyGenerator
and make it part of the reactive pipeline despite the limitations of the underlying cache contract (which focuses on asynchronous retrieval of values for pre-determined keys), let's open #31973 accordingly.