From a7db7d289a14cc93aeb350920a93417a252605dc Mon Sep 17 00:00:00 2001 From: Harrison Date: Sat, 25 Apr 2020 01:32:01 -0500 Subject: [PATCH] Caching now has a fresh importance factor. --- .../recrown/islandsurvivalcraft/caching/Cache.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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);