diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java index d73b130cbd2..db9dd4d92e4 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java @@ -69,8 +69,8 @@ public class CaffeineCache extends AbstractValueAdaptingCache { * given internal {@link com.github.benmanes.caffeine.cache.Cache} to use. * @param name the name of the cache * @param cache the backing Caffeine Cache instance - * @param allowNullValues whether to accept and convert {@code null} - * values for this cache + * @param allowNullValues whether to accept and convert {@code null} values + * for this cache */ public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache cache, boolean allowNullValues) { @@ -86,9 +86,9 @@ public class CaffeineCache extends AbstractValueAdaptingCache { * Create a {@link CaffeineCache} instance with the specified name and the * given internal {@link AsyncCache} to use. * @param name the name of the cache - * @param cache the backing Caffeine Cache instance - * @param allowNullValues whether to accept and convert {@code null} - * values for this cache + * @param cache the backing Caffeine AsyncCache instance + * @param allowNullValues whether to accept and convert {@code null} values + * for this cache * @since 6.1 */ public CaffeineCache(String name, AsyncCache cache, boolean allowNullValues) { @@ -118,6 +118,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { /** * Return the internal Caffeine AsyncCache. * @throws IllegalStateException if no AsyncCache is available + * @since 6.1 * @see #CaffeineCache(String, AsyncCache, boolean) * @see CaffeineCacheManager#setAsyncCacheMode */ @@ -130,7 +131,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { @SuppressWarnings("unchecked") @Override @Nullable - public T get(Object key, final Callable valueLoader) { + public T get(Object key, Callable valueLoader) { return (T) fromStoreValue(this.cache.get(key, new LoadFunction(valueLoader))); } @@ -166,7 +167,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { @Override @Nullable - public ValueWrapper putIfAbsent(Object key, @Nullable final Object value) { + public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { PutIfAbsentFunction callable = new PutIfAbsentFunction(value); Object result = this.cache.get(key, callable); return (callable.called ? null : toValueWrapper(result)); @@ -200,7 +201,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { @Nullable private final Object value; - private boolean called; + boolean called; public PutIfAbsentFunction(@Nullable Object value) { this.value = value; @@ -219,16 +220,17 @@ public class CaffeineCache extends AbstractValueAdaptingCache { private final Callable valueLoader; public LoadFunction(Callable valueLoader) { + Assert.notNull(valueLoader, "Callable must not be null"); this.valueLoader = valueLoader; } @Override - public Object apply(Object o) { + public Object apply(Object key) { try { return toStoreValue(this.valueLoader.call()); } catch (Exception ex) { - throw new ValueRetrievalException(o, this.valueLoader, ex); + throw new ValueRetrievalException(key, this.valueLoader, ex); } } } diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java index bd2c2415c40..44220ba8609 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java @@ -276,12 +276,12 @@ public class CaffeineCacheManager implements CacheManager { *

This allows for custom settings per cache (as opposed to all caches * sharing the common settings in the cache manager's configuration) and * is typically used with the Caffeine builder API: - * {@code registerCustomCache("myCache", Caffeine.newBuilder().maximumSize(10).build())} + * {@code registerCustomCache("myCache", Caffeine.newBuilder().maximumSize(10).buildAsync())} *

Note that any other caches, whether statically specified through * {@link #setCacheNames} or dynamically built on demand, still operate * with the common settings in the cache manager's configuration. * @param name the name of the cache - * @param cache the custom Caffeine Cache instance to register + * @param cache the custom Caffeine AsyncCache instance to register * @since 6.1 * @see #adaptCaffeineCache(String, AsyncCache) */