Skip to content

Commit c9849d6

Browse files
committed
Polishing
(cherry picked from commit 3a9e0ea)
1 parent 790abed commit c9849d6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,8 +59,8 @@ public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Objec
5959
* given internal {@link com.github.benmanes.caffeine.cache.Cache} to use.
6060
* @param name the name of the cache
6161
* @param cache the backing Caffeine Cache instance
62-
* @param allowNullValues whether to accept and convert {@code null}
63-
* values for this cache
62+
* @param allowNullValues whether to accept and convert {@code null} values
63+
* for this cache
6464
*/
6565
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache,
6666
boolean allowNullValues) {
@@ -86,7 +86,7 @@ public final com.github.benmanes.caffeine.cache.Cache<Object, Object> getNativeC
8686
@SuppressWarnings("unchecked")
8787
@Override
8888
@Nullable
89-
public <T> T get(Object key, final Callable<T> valueLoader) {
89+
public <T> T get(Object key, Callable<T> valueLoader) {
9090
return (T) fromStoreValue(this.cache.get(key, new LoadFunction(valueLoader)));
9191
}
9292

@@ -106,7 +106,7 @@ public void put(Object key, @Nullable Object value) {
106106

107107
@Override
108108
@Nullable
109-
public ValueWrapper putIfAbsent(Object key, @Nullable final Object value) {
109+
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
110110
PutIfAbsentFunction callable = new PutIfAbsentFunction(value);
111111
Object result = this.cache.get(key, callable);
112112
return (callable.called ? null : toValueWrapper(result));
@@ -140,7 +140,7 @@ private class PutIfAbsentFunction implements Function<Object, Object> {
140140
@Nullable
141141
private final Object value;
142142

143-
private boolean called;
143+
boolean called;
144144

145145
public PutIfAbsentFunction(@Nullable Object value) {
146146
this.value = value;
@@ -159,16 +159,17 @@ private class LoadFunction implements Function<Object, Object> {
159159
private final Callable<?> valueLoader;
160160

161161
public LoadFunction(Callable<?> valueLoader) {
162+
Assert.notNull(valueLoader, "Callable must not be null");
162163
this.valueLoader = valueLoader;
163164
}
164165

165166
@Override
166-
public Object apply(Object o) {
167+
public Object apply(Object key) {
167168
try {
168169
return toStoreValue(this.valueLoader.call());
169170
}
170171
catch (Exception ex) {
171-
throw new ValueRetrievalException(o, this.valueLoader, ex);
172+
throw new ValueRetrievalException(key, this.valueLoader, ex);
172173
}
173174
}
174175
}

0 commit comments

Comments
 (0)