diff --git a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index 6b6a47fe..b94f4702 100644 --- a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -843,7 +843,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { return; } playerList = core.playerList; - sscache = new SnapshotCache(core.getSnapShotCacheSize()); + sscache = new SnapshotCache(core.getSnapShotCacheSize(), core.useSoftRefInSnapShotCache()); /* Get map manager from core */ mapManager = core.getMapManager(); diff --git a/src/main/java/org/dynmap/bukkit/SnapshotCache.java b/src/main/java/org/dynmap/bukkit/SnapshotCache.java index 6e8d38bc..73f1e404 100644 --- a/src/main/java/org/dynmap/bukkit/SnapshotCache.java +++ b/src/main/java/org/dynmap/bukkit/SnapshotCache.java @@ -3,6 +3,7 @@ package org.dynmap.bukkit; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; +import java.lang.ref.SoftReference; import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -20,9 +21,10 @@ public class SnapshotCache { private ReferenceQueue refqueue; private long cache_attempts; private long cache_success; - + private boolean softref; + private static class CacheRec { - WeakReference ref; + Reference ref; boolean hasbiome; boolean hasrawbiome; boolean hasblockdata; @@ -32,12 +34,12 @@ public class SnapshotCache { @SuppressWarnings("serial") public class CacheHashMap extends LinkedHashMap { private int limit; - private IdentityHashMap, String> reverselookup; + private IdentityHashMap, String> reverselookup; public CacheHashMap(int lim) { super(16, (float)0.75, true); limit = lim; - reverselookup = new IdentityHashMap, String>(); + reverselookup = new IdentityHashMap, String>(); } protected boolean removeEldestEntry(Map.Entry last) { boolean remove = (size() >= limit); @@ -51,9 +53,10 @@ public class SnapshotCache { /** * Create snapshot cache */ - public SnapshotCache(int max_size) { + public SnapshotCache(int max_size, boolean softref) { snapcache = new CacheHashMap(max_size); refqueue = new ReferenceQueue(); + this.softref = softref; } private String getKey(String w, int cx, int cz) { return w + ":" + cx + ":" + cz; @@ -127,7 +130,10 @@ public class SnapshotCache { rec.hasbiome = biome; rec.hasrawbiome = biomeraw; rec.hashighesty = highesty; - rec.ref = new WeakReference(ss, refqueue); + if (softref) + rec.ref = new SoftReference(ss, refqueue); + else + rec.ref = new WeakReference(ss, refqueue); CacheRec prevrec = snapcache.put(key, rec); if(prevrec != null) { snapcache.reverselookup.remove(prevrec.ref); diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index a3ff9def..3e7378e4 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -412,6 +412,11 @@ custom-commands: preupdatecommand: "" # Command run just after any image file is written or updated: run with single parameter with fully qualified file name postupdatecommand: "" + +# Snapshot cache size, in chunks +snapshotcachesize: 500 +# Snapshot cache uses soft references (true), else weak references (false) +soft-ref-cache: true # Set to true to enable verbose startup messages - can help with debugging map configuration problems # Set to false for a much quieter startup log