mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-02 16:49:56 +01:00
Added configuration caching.
This commit is contained in:
parent
c1603f1060
commit
e771d94f24
@ -11,23 +11,26 @@ import org.dynmap.web.Json;
|
|||||||
|
|
||||||
public class ClientConfigurationHandler implements HttpHandler {
|
public class ClientConfigurationHandler implements HttpHandler {
|
||||||
private Map<?, ?> configuration;
|
private Map<?, ?> configuration;
|
||||||
|
private byte[] cachedConfiguration = null;
|
||||||
public ClientConfigurationHandler(Map<?, ?> configuration) {
|
public ClientConfigurationHandler(Map<?, ?> configuration) {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
||||||
String s = Json.stringifyJson(configuration);
|
if (cachedConfiguration == null) {
|
||||||
|
String s = Json.stringifyJson(configuration);
|
||||||
byte[] bytes = s.getBytes();
|
|
||||||
|
cachedConfiguration = s.getBytes();
|
||||||
|
}
|
||||||
String dateStr = new Date().toString();
|
String dateStr = new Date().toString();
|
||||||
|
|
||||||
response.fields.put("Date", dateStr);
|
response.fields.put("Date", dateStr);
|
||||||
response.fields.put("Content-Type", "text/plain");
|
response.fields.put("Content-Type", "text/plain");
|
||||||
response.fields.put("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
|
response.fields.put("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
|
||||||
response.fields.put("Last-modified", dateStr);
|
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());
|
BufferedOutputStream out = new BufferedOutputStream(response.getBody());
|
||||||
out.write(s.getBytes());
|
out.write(cachedConfiguration);
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user