From b8d44ff60c5cd6db6b971e2206cf18b5420a95cb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 18 Mar 2011 09:05:47 +0000 Subject: watcher: set Expires headers for cache invalidation We know exactly when to invalidate based on the delay :) --- lib/raindrops/watcher.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb index 52a8eff..3c724b9 100644 --- a/lib/raindrops/watcher.rb +++ b/lib/raindrops/watcher.rb @@ -168,14 +168,14 @@ class Raindrops::Watcher def active_stats(addr) # :nodoc: @lock.synchronize do tmp = @active[addr] or return - [ @resets[addr], tmp.dup ] + [ @snapshot[0], @resets[addr], tmp.dup ] end end def queued_stats(addr) # :nodoc: @lock.synchronize do tmp = @queued[addr] or return - [ @resets[addr], tmp.dup ] + [ @snapshot[0], @resets[addr], tmp.dup ] end end @@ -200,16 +200,17 @@ class Raindrops::Watcher end def histogram_txt(agg) - reset_at, agg = *agg + updated_at, reset_at, agg = *agg headers = agg_to_hash(reset_at, agg) body = agg.to_s headers["Content-Type"] = "text/plain" + headers["Expires"] = (updated_at + @delay).httpdate headers["Content-Length"] = bytesize(body).to_s [ 200, headers, [ body ] ] end def histogram_html(agg, addr) - reset_at, agg = *agg + updated_at, reset_at, agg = *agg headers = agg_to_hash(reset_at, agg) body = "" \ "#{hostname} - #{escape_html addr}" \ @@ -221,6 +222,7 @@ class Raindrops::Watcher "" \ "" headers["Content-Type"] = "text/html" + headers["Expires"] = (updated_at + @delay).httpdate headers["Content-Length"] = bytesize(body).to_s [ 200, headers, [ body ] ] end @@ -286,6 +288,7 @@ class Raindrops::Watcher headers = { "Content-Type" => "text/html", "Last-Modified" => updated_at.httpdate, + "Expires" => (updated_at + @delay).httpdate, } body = "" \ "#{hostname} - all interfaces" \ @@ -342,6 +345,7 @@ class Raindrops::Watcher headers = { "Content-Type" => "text/plain", "Cache-Control" => "no-transform", + "Expires" => Time.at(0).httpdate, } headers["Transfer-Encoding"] = "chunked" if @chunk [ 200, headers, self ] -- cgit v1.2.3-24-ge0c7