commit 163ee8c8472ce13e6e1e589d245b102c7d684a67 Author: Karsten Loesing karsten.loesing@gmx.net Date: Fri Mar 9 13:56:35 2012 +0100
Implement caching using Last-Modified/If-Modified-Since headers. --- src/org/torproject/onionoo/Main.java | 16 ++++++++-------- src/org/torproject/onionoo/ResourceServlet.java | 7 ++++++- web/index.html | 8 +++----- 3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/org/torproject/onionoo/Main.java b/src/org/torproject/onionoo/Main.java index 8c4497d..20367d2 100644 --- a/src/org/torproject/onionoo/Main.java +++ b/src/org/torproject/onionoo/Main.java @@ -17,14 +17,6 @@ public class Main { cn.setBridgeRunningBits(); cn.writeRelaySearchDataFile();
- printStatus("Updating summary data."); - SummaryDataWriter sdw = new SummaryDataWriter(); - sdw.setLastValidAfterMillis(cn.getLastValidAfterMillis()); - sdw.setLastPublishedMillis(cn.getLastPublishedMillis()); - sdw.setCurrentRelays(cn.getCurrentRelays()); - sdw.setCurrentBridges(cn.getCurrentBridges()); - sdw.writeSummaryDataFile(); - printStatus("Updating detail data."); DetailDataWriter ddw = new DetailDataWriter(); ddw.setCurrentRelays(cn.getCurrentRelays()); @@ -42,6 +34,14 @@ public class Main { bdw.readExtraInfoDescriptors(); bdw.deleteObsoleteBandwidthFiles();
+ printStatus("Updating summary data."); + SummaryDataWriter sdw = new SummaryDataWriter(); + sdw.setLastValidAfterMillis(cn.getLastValidAfterMillis()); + sdw.setLastPublishedMillis(cn.getLastPublishedMillis()); + sdw.setCurrentRelays(cn.getCurrentRelays()); + sdw.setCurrentBridges(cn.getCurrentBridges()); + sdw.writeSummaryDataFile(); + printStatus("Terminating."); }
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java index 016c9ef..b28eca1 100644 --- a/src/org/torproject/onionoo/ResourceServlet.java +++ b/src/org/torproject/onionoo/ResourceServlet.java @@ -26,7 +26,7 @@ public class ResourceServlet extends HttpServlet { this.readSummaryFile(); }
- long summaryFileLastModified = 0L; + long summaryFileLastModified = -1L; boolean readSummaryFile = false; private String relaysPublishedLine = null, bridgesPublishedLine = null; private List<String> relayLines = new ArrayList<String>(), @@ -69,6 +69,11 @@ public class ResourceServlet extends HttpServlet { this.readSummaryFile = true; }
+ public long getLastModified(HttpServletRequest request) { + this.readSummaryFile(); + return this.summaryFileLastModified; + } + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
diff --git a/web/index.html b/web/index.html index 27bb094..ff781f6 100755 --- a/web/index.html +++ b/web/index.html @@ -16,11 +16,9 @@ responds with JSON-formatted replies.</p> gzip"</i> header in their requests and handle gzip-compressed responses. Only requests starting at a certain size will be compressed by the server.</li> -<li><b>Caching:</b> Clients should cache all responses for up to five -minutes. -A better caching strategy may be employed in the future that will be based -on the server's information when new data is expected to be -available.</li> +<li><b>Caching:</b> Clients should make use of the <i>"Last-Modified"</i> +header of responses and include that timestamp in a +<i>"If-Modified-Since"</i> header of subsequent requests.</li> <li><b>Protocol changes:</b> There are plenty of reasons why we may have to change the protocol described here. Clients should be able to handle all valid JSON responses, ignoring
tor-commits@lists.torproject.org