Hello Ryan,

Thanks a lot for your in-depth explanation.

If I understand you correctly, if I specify :
   response.headers['Cache-Control'] = "public, must-revalidate"
or
   expires_in 0, :public => true

then the backend will be asked if the content is still fresh for every
request, but the backend will only generate a new response if the etag
has changed (if the etag hasn't changed, a 304 not-modified header
will be sent and the content will be served from the cache, as in the
last drawing in your article :
http://tomayko.com/writings/things-caches-do )

I tried both solutions, and here are my results :

* expires_in 0 :
 - with Safari, the page doesn't seem to be served from the cache
 - with Firefox, the page is served from the cache and correctly
expired when I create a new item, it is working as expected

* response.headers['Cache-Control'] = "must-revalidate"
 - with Safari and Firefox : the page is cached but not expired when I
create a new item

Again, a 15.2Mb screencast that shows it in details :
http://dl.getdropbox.com/u/40466/tmp/heroku-caching-2.mov

Do you have any idea?

Thanks again for your help,
Thomas.

On Wed, Aug 26, 2009 at 11:00 PM, Ryan Tomayko<[email protected]> wrote:
>
> On Fri, Aug 21, 2009 at 10:02 AM, Thomas Balthazar<[email protected]> 
> wrote:
>>
>> Hello,
>>
>> I'm trying to use HTTP caching in my Rails 2.3.3 app, but the result
>> is that my pages are always served from the cache even if there is a
>> newer content.
>>
>> I've created a simple Rails app with only one controller to illustrate
>> my problem :
>>
>> 1/ Go here, and you'll see a list of 'items' :
>> http://test-caching.heroku.com/
>>
>> 2/ Create a new item :
>> http://test-caching.heroku.com/items/new
>>
>> 3/ Go back to the list and you won't see the newly created item
>> because the page is served from the cache :
>> http://test-caching.heroku.com/
>>
>> Here is a small screencast (8.8Mb) that shows the problem :
>> http://dl.getdropbox.com/u/40466/tmp/heroku-caching.mov
>>
>> Here is the code of the app hosted on Github :
>> http://github.com/suitmymind/heroku-caching/tree/master
>>
>> And the 'caching' code can be found here (lines 8 and 10) :
>> http://github.com/suitmymind/heroku-caching/blob/c7a76c40feda96b357f1d3ef4b09e4f7586add3a/app/controllers/items_controller.rb#L8
>>
>> Any idea?
>> What am I doing wrong?
>> Thanks a lot for your suggestions.
>
> Hi Thomas,
>
> Thanks for the detailed example. It looks like Varnish is assuming a
> default max-age of ~500 seconds since the Cache-Control header is set
> to public but no explicit max-age is specified and the must-revalidate
> directive isn't provided. redbot.org is an invaluable resource in
> debugging these types of issues:
>
> http://redbot.org/?uri=http%3A%2F%2Ftest-caching.heroku.com%2F
>
> Most HTTP caches support "heuristic expiration" (details here:
> http://tools.ietf.org/html/rfc2616#page-80). The basic idea is that,
> if no explicit expiration time/age is provided, the cache uses a
> heuristic to determine expiration, typically based on the
> Last-Modified header.
>
> You have a few options here. If you'd like to force the cache to
> always validate the response with the backend, you can set the
> "must-revalidate" cache-control directive. Somewhere before the call
> to stale?:
>
>    response.headers['Cache-Control'] = "public, must-revalidate"
>
> That tells the cache that it's not allowed to serve a stale response
> and that it must validate its version with the backend.
>
> Alternatively, you can set the max-age directive to zero. This has
> pretty much the same effect but looks a lot nicer because Rails has a
> controller method for it:
>
>    expires_in 0, :public => true
>
> Give those a shot and let me know what happens. I'm also not sure I
> like that Varnish does heuristic expiration by default, even though
> it's to spec.
>
> Thanks,
> Ryan
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to