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 {
|
} else {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
if (data.containsKey(key)) return;
|
||||||
CacheValue<K, V> val = new CacheValue<>();
|
CacheValue<K, V> val = new CacheValue<>();
|
||||||
val.key = key;
|
val.key = key;
|
||||||
val.value = value;
|
val.value = value;
|
||||||
|
@ -8,6 +8,7 @@ class CacheUsageStack<K, V> {
|
|||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
|
|
||||||
private void addValueToStackTop(CacheValue<K, V> value) {
|
private void addValueToStackTop(CacheValue<K, V> value) {
|
||||||
|
if (value == first) return;
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
first.front = value;
|
first.front = value;
|
||||||
value.back = first;
|
value.back = first;
|
||||||
@ -91,6 +92,7 @@ class CacheUsageStack<K, V> {
|
|||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
|
Loading…
Reference in New Issue
Block a user