-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Cacheable does not respect cache hit when empty Mono/Flux response is returned #31868
Comments
Spring Framework 6.1 has explicit support for reactive types (which wasn't really supported before). See #17920 |
But caching is working for everything except when the response is an empty flux, which was working in spring-boot 3.1.6 |
This comment has been minimized.
This comment has been minimized.
We mean to cache an empty list in such a case, and we do put that cache entry, but then we reinvoke the method in case of a cache hit with an empty publisher (which our unit test did not catch since it was only checking the cache entry itself). To be fixed for 6.1.3. |
As a side note: @fabioacsilva so you were actually caching In any case, as of 6.1, we attach to the reactive pipeline in order to cache the produced value (a list of values in case of a |
@jhoeller We were caching Flux instances with @Cacheable and Flux.cache(), example code:
We had some unit tests with a bunch of values and caught the empty list one with them. Thank you for your response |
This should be fixed in the upcoming 6.1.3 snapshot through an earlier It would be great if you could give such a snapshot a try from |
Hello,
Upon upgrading to spring-boot 3.2.0 and Java 21 our team noticed that our methods annotated with
@Cacheable
do not cache properly when the return is an empty Flux.Sample source code provided:
cacheable.zip
Using the past example if we hit the endpoint with anything other than "broken" we get the following log:
As we can see the service log is only called once due to the cache.
If we call it with "broken" we get the following log:
The service keeps getting called meaning the cache is not working properly.
If we revert to spring-boot 3.1.6 and Java 17 the behaviour is the one expected and the empty flux gets cached
The text was updated successfully, but these errors were encountered: