Polishing
This commit is contained in:
parent
4ce1ac0dcb
commit
3a9e0ea8a7
|
|
@ -59,8 +59,8 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
|
||||||
* given internal {@link com.github.benmanes.caffeine.cache.Cache} to use.
|
* given internal {@link com.github.benmanes.caffeine.cache.Cache} to use.
|
||||||
* @param name the name of the cache
|
* @param name the name of the cache
|
||||||
* @param cache the backing Caffeine Cache instance
|
* @param cache the backing Caffeine Cache instance
|
||||||
* @param allowNullValues whether to accept and convert {@code null}
|
* @param allowNullValues whether to accept and convert {@code null} values
|
||||||
* values for this cache
|
* for this cache
|
||||||
*/
|
*/
|
||||||
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache,
|
public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Object, Object> cache,
|
||||||
boolean allowNullValues) {
|
boolean allowNullValues) {
|
||||||
|
|
@ -86,7 +86,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public <T> T get(Object key, final Callable<T> valueLoader) {
|
public <T> T get(Object key, Callable<T> valueLoader) {
|
||||||
return (T) fromStoreValue(this.cache.get(key, new LoadFunction(valueLoader)));
|
return (T) fromStoreValue(this.cache.get(key, new LoadFunction(valueLoader)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ValueWrapper putIfAbsent(Object key, @Nullable final Object value) {
|
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
|
||||||
PutIfAbsentFunction callable = new PutIfAbsentFunction(value);
|
PutIfAbsentFunction callable = new PutIfAbsentFunction(value);
|
||||||
Object result = this.cache.get(key, callable);
|
Object result = this.cache.get(key, callable);
|
||||||
return (callable.called ? null : toValueWrapper(result));
|
return (callable.called ? null : toValueWrapper(result));
|
||||||
|
|
@ -140,7 +140,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
private boolean called;
|
boolean called;
|
||||||
|
|
||||||
public PutIfAbsentFunction(@Nullable Object value) {
|
public PutIfAbsentFunction(@Nullable Object value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
@ -159,16 +159,17 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
|
||||||
private final Callable<?> valueLoader;
|
private final Callable<?> valueLoader;
|
||||||
|
|
||||||
public LoadFunction(Callable<?> valueLoader) {
|
public LoadFunction(Callable<?> valueLoader) {
|
||||||
|
Assert.notNull(valueLoader, "Callable must not be null");
|
||||||
this.valueLoader = valueLoader;
|
this.valueLoader = valueLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object apply(Object o) {
|
public Object apply(Object key) {
|
||||||
try {
|
try {
|
||||||
return toStoreValue(this.valueLoader.call());
|
return toStoreValue(this.valueLoader.call());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new ValueRetrievalException(o, this.valueLoader, ex);
|
throw new ValueRetrievalException(key, this.valueLoader, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue