mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-02-26 08:41:33 +01:00
Add softref option for chunk snapshot cache
This commit is contained in:
parent
5bc4de6a8b
commit
b85c38e3a7
@ -843,7 +843,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerList = core.playerList;
|
playerList = core.playerList;
|
||||||
sscache = new SnapshotCache(core.getSnapShotCacheSize());
|
sscache = new SnapshotCache(core.getSnapShotCacheSize(), core.useSoftRefInSnapShotCache());
|
||||||
|
|
||||||
/* Get map manager from core */
|
/* Get map manager from core */
|
||||||
mapManager = core.getMapManager();
|
mapManager = core.getMapManager();
|
||||||
|
@ -3,6 +3,7 @@ package org.dynmap.bukkit;
|
|||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.ReferenceQueue;
|
import java.lang.ref.ReferenceQueue;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -20,9 +21,10 @@ public class SnapshotCache {
|
|||||||
private ReferenceQueue<SnapshotRec> refqueue;
|
private ReferenceQueue<SnapshotRec> refqueue;
|
||||||
private long cache_attempts;
|
private long cache_attempts;
|
||||||
private long cache_success;
|
private long cache_success;
|
||||||
|
private boolean softref;
|
||||||
|
|
||||||
private static class CacheRec {
|
private static class CacheRec {
|
||||||
WeakReference<SnapshotRec> ref;
|
Reference<SnapshotRec> ref;
|
||||||
boolean hasbiome;
|
boolean hasbiome;
|
||||||
boolean hasrawbiome;
|
boolean hasrawbiome;
|
||||||
boolean hasblockdata;
|
boolean hasblockdata;
|
||||||
@ -32,12 +34,12 @@ public class SnapshotCache {
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class CacheHashMap extends LinkedHashMap<String, CacheRec> {
|
public class CacheHashMap extends LinkedHashMap<String, CacheRec> {
|
||||||
private int limit;
|
private int limit;
|
||||||
private IdentityHashMap<WeakReference<SnapshotRec>, String> reverselookup;
|
private IdentityHashMap<Reference<SnapshotRec>, String> reverselookup;
|
||||||
|
|
||||||
public CacheHashMap(int lim) {
|
public CacheHashMap(int lim) {
|
||||||
super(16, (float)0.75, true);
|
super(16, (float)0.75, true);
|
||||||
limit = lim;
|
limit = lim;
|
||||||
reverselookup = new IdentityHashMap<WeakReference<SnapshotRec>, String>();
|
reverselookup = new IdentityHashMap<Reference<SnapshotRec>, String>();
|
||||||
}
|
}
|
||||||
protected boolean removeEldestEntry(Map.Entry<String, CacheRec> last) {
|
protected boolean removeEldestEntry(Map.Entry<String, CacheRec> last) {
|
||||||
boolean remove = (size() >= limit);
|
boolean remove = (size() >= limit);
|
||||||
@ -51,9 +53,10 @@ public class SnapshotCache {
|
|||||||
/**
|
/**
|
||||||
* Create snapshot cache
|
* Create snapshot cache
|
||||||
*/
|
*/
|
||||||
public SnapshotCache(int max_size) {
|
public SnapshotCache(int max_size, boolean softref) {
|
||||||
snapcache = new CacheHashMap(max_size);
|
snapcache = new CacheHashMap(max_size);
|
||||||
refqueue = new ReferenceQueue<SnapshotRec>();
|
refqueue = new ReferenceQueue<SnapshotRec>();
|
||||||
|
this.softref = softref;
|
||||||
}
|
}
|
||||||
private String getKey(String w, int cx, int cz) {
|
private String getKey(String w, int cx, int cz) {
|
||||||
return w + ":" + cx + ":" + cz;
|
return w + ":" + cx + ":" + cz;
|
||||||
@ -127,6 +130,9 @@ public class SnapshotCache {
|
|||||||
rec.hasbiome = biome;
|
rec.hasbiome = biome;
|
||||||
rec.hasrawbiome = biomeraw;
|
rec.hasrawbiome = biomeraw;
|
||||||
rec.hashighesty = highesty;
|
rec.hashighesty = highesty;
|
||||||
|
if (softref)
|
||||||
|
rec.ref = new SoftReference<SnapshotRec>(ss, refqueue);
|
||||||
|
else
|
||||||
rec.ref = new WeakReference<SnapshotRec>(ss, refqueue);
|
rec.ref = new WeakReference<SnapshotRec>(ss, refqueue);
|
||||||
CacheRec prevrec = snapcache.put(key, rec);
|
CacheRec prevrec = snapcache.put(key, rec);
|
||||||
if(prevrec != null) {
|
if(prevrec != null) {
|
||||||
|
@ -413,6 +413,11 @@ custom-commands:
|
|||||||
# Command run just after any image file is written or updated: run with single parameter with fully qualified file name
|
# Command run just after any image file is written or updated: run with single parameter with fully qualified file name
|
||||||
postupdatecommand: ""
|
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 true to enable verbose startup messages - can help with debugging map configuration problems
|
||||||
# Set to false for a much quieter startup log
|
# Set to false for a much quieter startup log
|
||||||
verbose: false
|
verbose: false
|
||||||
|
Loading…
Reference in New Issue
Block a user