Polishing.

Inline valueFromLoader method. Refine tests to not rely on the number of runtime CPU cores.

See #2079
Original pull request: #2082.
This commit is contained in:
Mark Paluch
2021-06-15 09:29:04 +02:00
parent 30aeda562b
commit ba767fa86d
2 changed files with 88 additions and 34 deletions

View File

@@ -132,13 +132,19 @@ public class RedisCache extends AbstractValueAdaptingCache {
@SuppressWarnings("unchecked")
private synchronized <T> T getSynchronized(Object key, Callable<T> valueLoader) {
ValueWrapper result = get(key);
if (result != null) {
return (T) result.get();
}
T value = valueFromLoader(key, valueLoader);
T value;
try {
value = valueLoader.call();
} catch (Exception e) {
throw new ValueRetrievalException(key, valueLoader, e);
}
put(key, value);
return value;
}
@@ -391,12 +397,4 @@ public class RedisCache extends AbstractValueAdaptingCache {
return cacheConfig.getKeyPrefixFor(name) + key;
}
private static <T> T valueFromLoader(Object key, Callable<T> valueLoader) {
try {
return valueLoader.call();
} catch (Exception e) {
throw new ValueRetrievalException(key, valueLoader, e);
}
}
}