Fixed - RLocalCachedMap.getAll() method doesn't respect storeCacheMiss setting #4218

pull/4226/head
Nikita Koksharov 3 years ago
parent 1141dae91c
commit 14abe1e5ec

@ -599,6 +599,7 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
Map<K, V> result = new HashMap<K, V>(); Map<K, V> result = new HashMap<K, V>();
Set<K> mapKeys = new HashSet<K>(keys); Set<K> mapKeys = new HashSet<K>(keys);
Set<K> missedKeys = new HashSet<>();
for (Iterator<K> iterator = mapKeys.iterator(); iterator.hasNext();) { for (Iterator<K> iterator = mapKeys.iterator(); iterator.hasNext();) {
K key = iterator.next(); K key = iterator.next();
CacheKey cacheKey = localCacheView.toCacheKey(key); CacheKey cacheKey = localCacheView.toCacheKey(key);
@ -608,6 +609,8 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
result.put(key, (V) value.getValue()); result.put(key, (V) value.getValue());
} }
iterator.remove(); iterator.remove();
} else {
missedKeys.add(key);
} }
} }
@ -616,24 +619,21 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
return new CompletableFutureWrapper<>(result); return new CompletableFutureWrapper<>(result);
} }
Set<K> newKeys = new HashSet<>(keys); if (!missedKeys.isEmpty()) {
newKeys.removeAll(result.keySet()); CompletionStage<Map<K, V>> f = loadAllAsync(missedKeys, false, 1, result)
if (!newKeys.isEmpty()) {
CompletionStage<Map<K, V>> f = loadAllAsync(newKeys, false, 1, result)
.thenApply(r -> result); .thenApply(r -> result);
return new CompletableFutureWrapper<>(f); return new CompletableFutureWrapper<>(f);
} }
return new CompletableFutureWrapper<>(result); return new CompletableFutureWrapper<>(result);
} }
RFuture<Map<K, V>> future = super.getAllAsync(mapKeys); RFuture<Map<K, V>> future = super.getAllAsync(missedKeys);
CompletionStage<Map<K, V>> f = future.thenApply(map -> { CompletionStage<Map<K, V>> f = future.thenApply(map -> {
result.putAll(map); result.putAll(map);
cacheMap(map); cacheMap(map);
if (storeCacheMiss) { if (storeCacheMiss) {
mapKeys.stream() missedKeys.stream()
.filter(key -> !map.containsKey(key)) .filter(key -> !map.containsKey(key))
.forEach(key -> { .forEach(key -> {
CacheKey cacheKey = localCacheView.toCacheKey(key); CacheKey cacheKey = localCacheView.toCacheKey(key);

Loading…
Cancel
Save