diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java b/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java index ce859da..cb48cf6 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java @@ -30,11 +30,11 @@ public class Cache { * @param value The value to store. */ public void set(K key, V value) { - writeLock.lock(); - try { - if (data.containsKey(key)) { - data.get(key).value = value; - } else { + if (data.containsKey(key)) { + data.get(key).value = value; + } else { + writeLock.lock(); + try { CacheValue val = new CacheValue<>(); val.key = key; val.value = value; @@ -43,9 +43,9 @@ public class Cache { if (data.size() > maxSize) { data.remove(usage.pop().key); } + } finally { + writeLock.unlock(); } - } finally { - writeLock.unlock(); } }