Added fix for another potential multithreaded case for cache.
Case: consecutive gets.
This commit is contained in:
parent
83297a1d10
commit
c60e94728e
@ -31,6 +31,7 @@ public class Cache<K, V> {
|
||||
} else {
|
||||
lock.lock();
|
||||
try {
|
||||
if (data.containsKey(key)) return;
|
||||
CacheValue<K, V> val = new CacheValue<>();
|
||||
val.key = key;
|
||||
val.value = value;
|
||||
|
@ -8,6 +8,7 @@ class CacheUsageStack<K, V> {
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
private void addValueToStackTop(CacheValue<K, V> value) {
|
||||
if (value == first) return;
|
||||
if (first != null) {
|
||||
first.front = value;
|
||||
value.back = first;
|
||||
@ -91,6 +92,7 @@ class CacheUsageStack<K, V> {
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
size = 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
|
Loading…
Reference in New Issue
Block a user