On Mon, Sep 14, 2009 at 2:00 PM, KD <
inbo...@gmail.com> wrote:
> HTTP Caching was new to me (as was most of this stack), but I was able
> to quickly get rack:cache working in my Sinatra app with the response
> ["Cache-Control"] = "max-age=30, public". Unfortunately, my
> underlying content can change quite a bit via other means and the
> hardcoded max-age simply doesn't cut it when my page content must
> reflect the change.
>
> It looks like etag might be an answer, but I can't find much doc on
> its usage in sinatra. In my sinatra route I tried:
>
> get '/someroute' do
> etag "foo"
> erb :someview
> end
>
> I guessed i thought the above would halt prior to the erb line when
> accessed following the initial call. Of course, I wouldn't hardcode
> the etag value in real code.
That's exactly how etag works in Sinatra. When the If-None-Match
request header matches the ETag provided, the route is halted with 304
Not Modified response. Rack::Cache will serve the response from cache
for another 30s afterward. You can also set the Cache-Control header
here to extend the life of the cache further. e.g.,