Skip to content

RedisCache should expose ValueWrapper for cached null values returned from retrieve(key) #2783

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

Closed
jhoeller opened this issue Nov 22, 2023 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@jhoeller
Copy link

Following up on spring-projects/spring-framework#31637, the core caching infrastructure is able to handle the current RedisCache.retrieve(key) implementation now, making Spring Framework 6.1.1 compatible with the latest Spring Data Redis.

However, there is one remaining concern: RedisCache has support for nullable cache values but currently does not differentiate between a late-determined cache miss - indicated by null as a CompletableFuture value - and null as a cached value, effectively treating a cached null value as a cache miss. You may address this through the retrieve(key) implementation returning a CompletableFuture with a ValueWrapper that holds the nullable value. Since you derive from AbstractValueAdaptingCache anyway, you could simply call toValueWrapper(value) before passing it into the CompletableFuture.

Note that technically just actual null values have to be wrapped in a ValueWrapper while regular values may be exposed directly as a CompletableFuture value. In CaffeineCacheManager, we consistently expose ValueWrapper in case of allowNullValues=true, while we rather expose the regular values in case of allowNullValues=false (where we can expose the Caffeine-provided CompletableFuture directly without post-processing then). The common cache infrastructure can deal with any variant of the cache implementation here, so RedisCache may choose whatever makes sense for it - as long as actual null values are wrapped as a minimum.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2023
@christophstrobl christophstrobl removed the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2023
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 22, 2023
@mp911de mp911de self-assigned this Nov 22, 2023
@mp911de
Copy link
Member

mp911de commented Nov 22, 2023

Thanks a lot for bringing this up. It is indeed a gap and aligning with ValueWrapper makes sense.

@mp911de mp911de added this to the 3.2.1 (2023.1.1) milestone Nov 23, 2023
christophstrobl pushed a commit that referenced this issue Dec 14, 2023
…bsent cache mapping.

We now use ValueWrapper to differentiate in the async API between cache misses and cached null values.

Closes: #2783
Original Pull Request: #2785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
4 participants