I have an action which I cache using
caches_action :my_action, :expires_in=>1.hours
and also set the expires headers in the action itself using
def my_action
...
expires_in 1.hours
send_data(...,:disposition => 'inline',:type => 'image/png',:filename => params[:title]+".png")
end
However, when I look at the cache control response header from a result that is coming as the result of a memcached hit, I get this:
Cache-Control: private, max-age=0, must-revalidate
The first time round, i.e. when there is nothing in the cache, it is what I expect, i.e.:
Cache-Control: max-age=3600, private
It looks like rails+memcached is neither caching the original response headers, nor setting appropriate headers itself. The result is that the client makes a request to the server each time even when the result (an image) hasn't changed. Though the action completes quickly as it gets a hit in the cache, it still winds up sending all the data again, which I'd like to avoid.
How do I get the headers to do the right thing so that the client either makes no request in the first place, or gets a 'not modified' response?