diff --git a/redisson/src/main/java/org/redisson/misc/LFUCacheMap.java b/redisson/src/main/java/org/redisson/misc/LFUCacheMap.java index 1a1449926..49b6a2d1d 100644 --- a/redisson/src/main/java/org/redisson/misc/LFUCacheMap.java +++ b/redisson/src/main/java/org/redisson/misc/LFUCacheMap.java @@ -102,9 +102,9 @@ public class LFUCacheMap extends AbstractCacheMap { @Override protected void onValueRemove(CachedValue value) { - MapKey key = toKey((LFUCachedValue)value); - if (accessMap.remove(key) == null) { - throw new IllegalStateException(); + synchronized (value) { + MapKey key = toKey((LFUCachedValue)value); + accessMap.remove(key); } } @@ -116,7 +116,7 @@ public class LFUCacheMap extends AbstractCacheMap { MapKey key = toKey(value); if (accessMap.remove(key) == null) { - throw new IllegalStateException(); + return; } if (count < 0) { @@ -132,6 +132,9 @@ public class LFUCacheMap extends AbstractCacheMap { @Override protected void onMapFull() { Map.Entry entry = accessMap.pollFirstEntry(); + if (entry == null) { + return; + } map.remove(entry.getValue().getKey(), entry.getValue()); if (entry.getValue().accessCount == 0) { diff --git a/redisson/src/main/java/org/redisson/misc/LRUCacheMap.java b/redisson/src/main/java/org/redisson/misc/LRUCacheMap.java index c47ab0100..f526837ca 100644 --- a/redisson/src/main/java/org/redisson/misc/LRUCacheMap.java +++ b/redisson/src/main/java/org/redisson/misc/LRUCacheMap.java @@ -41,22 +41,27 @@ public class LRUCacheMap extends AbstractCacheMap { @Override protected void onValueRemove(CachedValue value) { - queue.remove(value); + synchronized (value) { + queue.remove(value); + } } @Override protected void onValueRead(CachedValue value) { // move value to tail of queue synchronized (value) { - queue.remove(value); - queue.add(value); + if (queue.remove(value)) { + queue.add(value); + } } } @Override protected void onMapFull() { CachedValue value = queue.poll(); - map.remove(value.getKey(), value); + if (value != null) { + map.remove(value.getKey(), value); + } } @Override