diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java b/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java index 1b3cb51..9a3c189 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/caching/Cache.java @@ -7,11 +7,21 @@ public class Cache { private final int maxCacheSize; private final HashMap> dataCache; private final PriorityQueue ids; + private final float freshImportanceFactor; - public Cache(int maxCacheSize) { + public Cache(int maxCacheSize, float freshImportanceFactor) { dataCache = new HashMap<>(maxCacheSize); ids = new PriorityQueue<>(maxCacheSize); this.maxCacheSize = maxCacheSize; + this.freshImportanceFactor = freshImportanceFactor; + } + + public Cache() { + this(1024, 1f); + } + + public Cache(int maxCacheSize) { + this(maxCacheSize, 1f); } public synchronized CacheValue retrieveCache(Identifier identifier) { @@ -27,7 +37,7 @@ public class Cache { } CacheValue value = new CacheValue<>(identifier); if (!ids.isEmpty()) { - identifier.usage += ids.peek().usage; + identifier.usage += ids.peek().usage * freshImportanceFactor; } ids.add(identifier); dataCache.put(identifier, value);