Revised handling of allowNullValues for asynchronous retrieval

Includes revised cacheNames javadoc and equals/hashCode for SimpleValueWrapper.

See gh-31637
This commit is contained in:
Juergen Hoeller
2023-11-22 12:22:13 +01:00
parent 5a3ad6b7c9
commit e64b81eec4
12 changed files with 147 additions and 38 deletions

View File

@@ -140,7 +140,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
public CompletableFuture<?> retrieve(Object key) {
CompletableFuture<?> result = getAsyncCache().getIfPresent(key);
if (result != null && isAllowNullValues()) {
result = result.handle((value, ex) -> fromStoreValue(value));
result = result.thenApply(this::toValueWrapper);
}
return result;
}

View File

@@ -48,9 +48,10 @@ import org.springframework.util.ObjectUtils;
* A {@link CaffeineSpec}-compliant expression value can also be applied
* via the {@link #setCacheSpecification "cacheSpecification"} bean property.
*
* <p>Supports the {@link Cache#retrieve(Object)} and
* <p>Supports the asynchronous {@link Cache#retrieve(Object)} and
* {@link Cache#retrieve(Object, Supplier)} operations through Caffeine's
* {@link AsyncCache}, when configured via {@link #setAsyncCacheMode}.
* {@link AsyncCache}, when configured via {@link #setAsyncCacheMode},
* with early-determined cache misses.
*
* <p>Requires Caffeine 3.0 or higher, as of Spring Framework 6.1.
*
@@ -198,6 +199,11 @@ public class CaffeineCacheManager implements CacheManager {
* <p>By default, this cache manager builds regular native Caffeine caches.
* To switch to async caches which can also be used through the synchronous API
* but come with support for {@code Cache#retrieve}, set this flag to {@code true}.
* <p>Note that while null values in the cache are tolerated in async cache mode,
* the recommendation is to disallow null values through
* {@link #setAllowNullValues setAllowNullValues(false)}. This makes the semantics
* of CompletableFuture-based access simpler and optimizes retrieval performance
* since a Caffeine-provided CompletableFuture handle does not have to get wrapped.
* @since 6.1
* @see Caffeine#buildAsync()
* @see Cache#retrieve(Object)