0.29.2 - Fix config caching

This commit is contained in:
Mike Primm 2012-01-11 14:07:36 +08:00 committed by mikeprimm
parent d7a7ee9c5d
commit a34ba56716
3 changed files with 6 additions and 3 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.dynmap</groupId>
<artifactId>dynmap</artifactId>
<version>0.30</version>
<version>0.29.2</version>
<name>dynmap</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -14,6 +14,8 @@ import org.json.simple.JSONObject;
public class ClientConfigurationHandler implements HttpHandler {
private DynmapPlugin plugin;
private byte[] cachedConfiguration = null;
private int cached_config_hashcode = 0;
public ClientConfigurationHandler(DynmapPlugin plugin) {
this.plugin = plugin;
plugin.events.addListener("worldactivated", new Event.Listener<DynmapWorld>() {
@ -25,13 +27,14 @@ public class ClientConfigurationHandler implements HttpHandler {
}
@Override
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
if (cachedConfiguration == null) {
if ((cachedConfiguration == null) || (plugin.getConfigHashcode() != cached_config_hashcode)) {
JSONObject configurationObject = new JSONObject();
plugin.events.<JSONObject>trigger("buildclientconfiguration", configurationObject);
String s = configurationObject.toJSONString();
cachedConfiguration = s.getBytes("UTF-8");
cached_config_hashcode = plugin.getConfigHashcode();
}
String dateStr = new Date().toString();

View File

@ -1,7 +1,7 @@
var config = {
// For internal server or proxying webserver.
url : {
configuration : 'up/configuration?_={timestamp}',
configuration : 'up/configuration',
update : 'up/world/{world}/{timestamp}',
sendmessage : 'up/sendmessage'
},