Gave newly cached items usage greater than the lowest.

This commit is contained in:
Harrison Deng 2020-04-25 01:15:38 -05:00
parent a412986044
commit 28b9a8005c

View File

@ -17,9 +17,8 @@ public class Cache <CacheValueType> {
public synchronized CacheValue<CacheValueType> retrieveCache(Identifier identifier) {
if (dataCache.containsKey(identifier)) {
ids.remove(identifier);
dataCache.get(identifier);
CacheValue<CacheValueType> val = dataCache.get(identifier);
val.getValue();
val.identifier.usage++;
ids.add(val.identifier);
return dataCache.get(identifier);
}
@ -27,6 +26,9 @@ public class Cache <CacheValueType> {
dataCache.remove(ids.poll());
}
CacheValue<CacheValueType> value = new CacheValue<>(identifier);
if (!ids.isEmpty()) {
identifier.usage += ids.peek().usage;
}
ids.add(identifier);
dataCache.put(identifier, value);