From e771d94f24f9ec0a5611e5364a7d38ee369049aa Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Tue, 1 Mar 2011 18:52:15 +0100 Subject: [PATCH] Added configuration caching. --- .../web/handlers/ClientConfigurationHandler.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/dynmap/web/handlers/ClientConfigurationHandler.java b/src/main/java/org/dynmap/web/handlers/ClientConfigurationHandler.java index 02cfdfa3..70659d85 100644 --- a/src/main/java/org/dynmap/web/handlers/ClientConfigurationHandler.java +++ b/src/main/java/org/dynmap/web/handlers/ClientConfigurationHandler.java @@ -11,23 +11,26 @@ import org.dynmap.web.Json; public class ClientConfigurationHandler implements HttpHandler { private Map configuration; + private byte[] cachedConfiguration = null; public ClientConfigurationHandler(Map configuration) { this.configuration = configuration; } @Override public void handle(String path, HttpRequest request, HttpResponse response) throws Exception { - String s = Json.stringifyJson(configuration); - - byte[] bytes = s.getBytes(); + if (cachedConfiguration == null) { + String s = Json.stringifyJson(configuration); + + cachedConfiguration = s.getBytes(); + } String dateStr = new Date().toString(); response.fields.put("Date", dateStr); response.fields.put("Content-Type", "text/plain"); response.fields.put("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); response.fields.put("Last-modified", dateStr); - response.fields.put("Content-Length", Integer.toString(bytes.length)); + response.fields.put("Content-Length", Integer.toString(cachedConfiguration.length)); BufferedOutputStream out = new BufferedOutputStream(response.getBody()); - out.write(s.getBytes()); + out.write(cachedConfiguration); out.flush(); } }