in jetcache-core/src/main/java/com/alicp/jetcache/LoadingCache.java [50:107]
public Map<K, V> getAll(Set<? extends K> keys) throws CacheInvokeException {
CacheLoader<K, V> loader = config.getLoader();
if (loader != null) {
MultiGetResult<K, V> r = GET_ALL(keys);
Map<K, V> kvMap;
if (r.isSuccess() || r.getResultCode() == CacheResultCode.PART_SUCCESS) {
kvMap = r.unwrapValues();
} else {
kvMap = new HashMap<>();
}
Set<K> keysNeedLoad = new LinkedHashSet<>();
keys.forEach((k) -> {
if (!kvMap.containsKey(k)) {
keysNeedLoad.add(k);
}
});
if (!config.isCachePenetrationProtect()) {
if (eventConsumer != null) {
loader = CacheUtil.createProxyLoader(cache, loader, eventConsumer);
}
Map<K, V> loadResult;
try {
loadResult = loader.loadAll(keysNeedLoad);
CacheLoader<K, V> theLoader = loader;
Map<K, V> updateValues = new HashMap<>();
loadResult.forEach((k,v)->{
if (needUpdate(v, theLoader)){
updateValues.put(k, v);
}
});
// batch put
if (!updateValues.isEmpty()) {
PUT_ALL(updateValues);
}
} catch (Throwable e) {
throw new CacheInvokeException(e);
}
kvMap.putAll(loadResult);
} else {
AbstractCache<K, V> abstractCache = CacheUtil.getAbstractCache(cache);
loader = CacheUtil.createProxyLoader(cache, loader, eventConsumer);
for(K key : keysNeedLoad) {
Consumer<V> cacheUpdater = (v) -> {
if(needUpdate(v, config.getLoader())) {
PUT(key, v);
}
};
V v = AbstractCache.synchronizedLoad(config, abstractCache, key, loader, cacheUpdater);
kvMap.put(key, v);
}
}
return kvMap;
} else {
return cache.getAll(keys);
}
}