My heroku website’s root page is essentially static, it has some ruby code in the view when its generated, but there’s nothing specific to a single user, so I’d like to have it cached by Varnish and served up without hitting my dyno (note that there are other pages that are dynamic in the application).
Heroku makes it seem very simple here. Just add response.headers['Cache-Control'] = 'public, max-age=300' and it’ll cache for 5 minutes before regenerating.
To test this I made the changed and outputted the date (Time.now) to the page, to see if it would remain the same for 5 minutes, but every time I access the page on a new browser it updates. Refreshing on the same browser works fine, but I think that’s because of the browser caching, not Heroku.
If it’s any help, when I do a curl -i to get the HTTP headers, I get this:
HTTP/1.1 200 OK^M
Server: nginx/0.7.67^M
Date: Thu, 29 Dec 2011 02:03:33 GMT^M
Content-Type: text/html; charset=utf-8^M
Connection: keep-alive^M
Cache-Control: public, max-age=300^M
X-Ua-Compatible: IE=Edge^M
Etag: "8a1b58f048968803980417a2914764d0"^M
X-Runtime: 0.038393^M
Content-Length: 8310^M
X-Varnish: 1040651825^M
Age: 0^M
Via: 1.1 varnish^M
Basically, I’d like to make sure that it’s generated once and then cached in Varnish, am I missing any options, do I have to configure something more? If you have other suggestions for serving a fast static page I’d love those as well.
Thanks!
The problem turned out to be that Heroku has a number of Varnish servers, so it takes about 10-15 page refreshes until the page was cached on all of the servers, after that it would stay cached. It was working all along, I just gave up after a few refreshes didn’t work.
I also increased the max_age so that I could see it more clearly, a 5 minute cache has almost no effect.