Revised handling of allowNullValues for asynchronous retrieval
Includes revised cacheNames javadoc and equals/hashCode for SimpleValueWrapper. See gh-31637
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user