Skip to content

Commit ba46d2b

Browse files
committed
Polishing
1 parent 27f9473 commit ba46d2b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Objec
6969
* given internal {@link com.github.benmanes.caffeine.cache.Cache} to use.
7070
* @param name the name of the cache
7171
* @param cache the backing Caffeine Cache instance
72-
* @param allowNullValues whether to accept and convert {@code null}
73-
* values for this cache
72+
* @param allowNullValues whether to accept and convert {@code null} values
73+
* for this cache
7474
*/
7575
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache,
7676
boolean allowNullValues) {
@@ -86,9 +86,9 @@ public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Objec
8686
* Create a {@link CaffeineCache} instance with the specified name and the
8787
* given internal {@link AsyncCache} to use.
8888
* @param name the name of the cache
89-
* @param cache the backing Caffeine Cache instance
90-
* @param allowNullValues whether to accept and convert {@code null}
91-
* values for this cache
89+
* @param cache the backing Caffeine AsyncCache instance
90+
* @param allowNullValues whether to accept and convert {@code null} values
91+
* for this cache
9292
* @since 6.1
9393
*/
9494
public CaffeineCache(String name, AsyncCache<Object, Object> cache, boolean allowNullValues) {
@@ -118,6 +118,7 @@ public final com.github.benmanes.caffeine.cache.Cache<Object, Object> getNativeC
118118
/**
119119
* Return the internal Caffeine AsyncCache.
120120
* @throws IllegalStateException if no AsyncCache is available
121+
* @since 6.1
121122
* @see #CaffeineCache(String, AsyncCache, boolean)
122123
* @see CaffeineCacheManager#setAsyncCacheMode
123124
*/
@@ -130,7 +131,7 @@ public final AsyncCache<Object, Object> getAsyncCache() {
130131
@SuppressWarnings("unchecked")
131132
@Override
132133
@Nullable
133-
public <T> T get(Object key, final Callable<T> valueLoader) {
134+
public <T> T get(Object key, Callable<T> valueLoader) {
134135
return (T) fromStoreValue(this.cache.get(key, new LoadFunction(valueLoader)));
135136
}
136137

@@ -166,7 +167,7 @@ public void put(Object key, @Nullable Object value) {
166167

167168
@Override
168169
@Nullable
169-
public ValueWrapper putIfAbsent(Object key, @Nullable final Object value) {
170+
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
170171
PutIfAbsentFunction callable = new PutIfAbsentFunction(value);
171172
Object result = this.cache.get(key, callable);
172173
return (callable.called ? null : toValueWrapper(result));
@@ -200,7 +201,7 @@ private class PutIfAbsentFunction implements Function<Object, Object> {
200201
@Nullable
201202
private final Object value;
202203

203-
private boolean called;
204+
boolean called;
204205

205206
public PutIfAbsentFunction(@Nullable Object value) {
206207
this.value = value;
@@ -219,16 +220,17 @@ private class LoadFunction implements Function<Object, Object> {
219220
private final Callable<?> valueLoader;
220221

221222
public LoadFunction(Callable<?> valueLoader) {
223+
Assert.notNull(valueLoader, "Callable must not be null");
222224
this.valueLoader = valueLoader;
223225
}
224226

225227
@Override
226-
public Object apply(Object o) {
228+
public Object apply(Object key) {
227229
try {
228230
return toStoreValue(this.valueLoader.call());
229231
}
230232
catch (Exception ex) {
231-
throw new ValueRetrievalException(o, this.valueLoader, ex);
233+
throw new ValueRetrievalException(key, this.valueLoader, ex);
232234
}
233235
}
234236
}

spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCacheManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ public void registerCustomCache(String name, com.github.benmanes.caffeine.cache.
276276
* <p>This allows for custom settings per cache (as opposed to all caches
277277
* sharing the common settings in the cache manager's configuration) and
278278
* is typically used with the Caffeine builder API:
279-
* {@code registerCustomCache("myCache", Caffeine.newBuilder().maximumSize(10).build())}
279+
* {@code registerCustomCache("myCache", Caffeine.newBuilder().maximumSize(10).buildAsync())}
280280
* <p>Note that any other caches, whether statically specified through
281281
* {@link #setCacheNames} or dynamically built on demand, still operate
282282
* with the common settings in the cache manager's configuration.
283283
* @param name the name of the cache
284-
* @param cache the custom Caffeine Cache instance to register
284+
* @param cache the custom Caffeine AsyncCache instance to register
285285
* @since 6.1
286286
* @see #adaptCaffeineCache(String, AsyncCache)
287287
*/

0 commit comments

Comments
 (0)