--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java 2011/12/22 20:30:28 1671 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java 2011/12/23 09:16:12 1672 @@ -24,6 +24,9 @@ Configuration loginConfig; Configuration homeConfig; + long cachedTime = 0; + String cachedXml = ""; + public StatusListener(Server server, Configuration loginConfig, Configuration homeConfig) { this.server = server; this.loginConfig = loginConfig; @@ -43,6 +46,24 @@ if(!event.path[0].equalsIgnoreCase("webstatus")) { return; } + + String xml; + long now = System.currentTimeMillis(); + if ( (now-cachedTime) > 5000) { + xml = buildXML(); + cachedXml = xml; + cachedTime = now; + } else { + xml = cachedXml; + } + + + event.setResponse(xml); + event.setActionTaken(true); + } + + private String buildXML() { + StringBuilder sb = new StringBuilder(); sb.append(" \n"); @@ -121,8 +142,8 @@ sb.append("\n"); sb.append(""); - event.setResponse(sb.toString()); - event.setActionTaken(true); + + return sb.toString(); }