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 -~----------~----~----~----~------~----~------~--~---
