I have my ruby app setup on Heroku using the Sinatra framework. The web server is unicorn and when a request finds its content in the cache of memcached (via the Dalli gem), it says cache: [GET /] fresh so it’s clearly retrieving content from the cache. However when I check the headers, the response code is always a 200 instead of a 304. I was under the impression that when a page is served from cache as it’s still fresh the response code should be 304.
Is this working as intended and I’m misunderstanding something? Does Unicorn just not give 304 codes when it finds something in the cache? Should I just not worry about this sort of thing?
Any guidance is appreciated.
Unicorn cannot know how your application handles caching. Therefore it cannot set etags for you.
Like Rajesh said, 304 is about browser cache.
You will have to generate an Etag hash in your app and then send it to the browser (via header).
According to this post browsers have support for etags : Browser support for eTags etags.
Here is the official doc on 304 : http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
Edit :
Take a look here to implement it with sinatra :
http://www.sinatrarb.com/intro#Cache%20Control
http://opensoul.org/blog/archives/2011/01/29/etags-with-memcached/