-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Redis cache is not supporting with null values #39547
Comments
/cc @cescoffier (redis), @gsmet (redis), @gwenneg (cache), @machi1990 (redis) |
Redis does not support 'null'. It's not part of the protocol. The semantic can be ambiguous:
This, I don't think we will fix it. |
@cescoffier Spring Cache SPI allows telling if we want to cache or ignore null values. Even if a null value can't be added into the key/value in a cache provider ( which is the case for Redis and Infinispan for example), we can add an special wrapper representing a null value. |
Concerning the null values the cache extension states: Null value caching is supported https://quarkus.io/guides/cache#negative-cache Some approaches to caching with annotations involve conditional caching through metadata. The provided annotations allow for the explicit caching of method returns based on certain conditions, including unless statements and options for caching null values. In our current cache extension, I believe a complex conditional caching mechanism might be unnecessary, at least for now. However, the issue of caching null returns versus non-null returns is a common problem worth considering. |
I don't believe we should encourage caching |
@cescoffier what if you want to cache unless it's null ? This is a common use case |
In this case, we would not cache |
As I said in my comment, the caching extension states that allows for storing null values, thus caching providers should do that too. However, there are cases where some methods return null, and caching that result is desirable, while in other cases, we prefer not to cache null to ensure method execution. This feature of conditional caching is commonly needed and enables us to control caching behavior as needed. |
I agree; that's the ambiguity behind |
Thanks for the details that you shared. @karesti @cescoffier What is the conclusion? Can you provide a flag to ignore null if we want? |
@amitgol1 No, no conclusion so far. I'm still not convinced that caching |
Describe the bug
In-memory cache :
Annotation of @CacheResult on method that return null value will throw exception from redis cache, how to put the redis cache in ignore mode fro null values?
Expected behavior
Ignore if value is null
Actual behavior
Exception about null in the cache
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: