Minor improvement to cache by reducing area under lock.
This commit is contained in:
parent
98e4265db7
commit
925296f326
@ -31,11 +31,11 @@ public class Cache<Key, Value> {
|
|||||||
if (data.size() > maxSize) {
|
if (data.size() > maxSize) {
|
||||||
int occ = 0;
|
int occ = 0;
|
||||||
do {
|
do {
|
||||||
cleaningLock.lock();
|
|
||||||
try {
|
|
||||||
Key potentialKey = occurrenceOrder.poll();
|
Key potentialKey = occurrenceOrder.poll();
|
||||||
CacheValue<Value> potential = data.get(potentialKey);
|
CacheValue<Value> potential = data.get(potentialKey);
|
||||||
potential.occurrence--;
|
potential.occurrence--;
|
||||||
|
cleaningLock.lock();
|
||||||
|
try {
|
||||||
occ = potential.occurrence;
|
occ = potential.occurrence;
|
||||||
if (occ < 1) {
|
if (occ < 1) {
|
||||||
data.remove(potentialKey);
|
data.remove(potentialKey);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user