fix bug: when error occurs during GET_ALL, loader is not invoked.
@@ -43,16 +43,16 @@ public class LoadingCache<K, V> extends SimpleProxyCache<K, V> {
if (r.isSuccess()) {
return r.getValue();
} else {
- Object loadedValue;
+ V loadedValue;
try {
loadedValue = loader.load(key);
} catch (Throwable e) {
throw new CacheInvokeException(e);
}
if (loadedValue != null || config.isCacheNullValue()) {
- PUT(key, (V) loadedValue);
+ PUT(key, loadedValue);
}
- return (V) loadedValue;
+ return loadedValue;
}
} else {
return cache.get(key);
@@ -67,8 +67,12 @@ public class LoadingCache<K, V> extends SimpleProxyCache<K, V> {
loader = CacheUtil.createProxyLoader(cache, loader, eventConsumer);
}
MultiGetResult<K, V> r = GET_ALL(keys);
+ Map<K, V> kvMap;
if (r.isSuccess() || r.getResultCode() == CacheResultCode.PART_SUCCESS) {
- Map<K, V> kvMap = r.unwrapValues();
+ kvMap = r.unwrapValues();
+ } else {
+ kvMap = new HashMap<>();
+ }
Set<K> keysNeedLoad = new HashSet<>();
keys.forEach((k) -> {
if (!kvMap.containsKey(k)) {
@@ -88,12 +92,8 @@ public class LoadingCache<K, V> extends SimpleProxyCache<K, V> {
} catch (Throwable e) {
throw new CacheInvokeException(e);
}
-
kvMap.putAll(loadResult);
return kvMap;
- } else {
- return new HashMap<>();
- }
} else {
return cache.getAll(keys);
}
