Rack is caching redirects

29 views
Skip to first unread message

Jason Fox

unread,
Nov 18, 2009, 3:23:22 PM11/18/09
to rack-cache
I have a strange problem with Rack-Cache and redirects that I can only
reproduce some of the time. Let me start by showing you what I found
cached in the "meta" when I was able to reproduce this problem
locally...

[[{"SERVER_NAME"=>"127.0.0.1",
"HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/
xml;q=0.9,*/*;q=0.8",
"HTTP_HOST"=>"127.0.0.1",
"HTTP_X_FORWARDED_HOST"=>"127.0.0.1",
"HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6;
en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5",
"REQUEST_PATH"=>"/signup/form/0",
"SERVER_PROTOCOL"=>"HTTP/1.1",
"HTTP_ACCEPT_LANGUAGE"=>"en-us,en;q=0.5",
"REMOTE_ADDR"=>"127.0.0.1",
"PATH_INFO"=>"/signup/form/0",
"SERVER_SOFTWARE"=>"Mongrel 1.1.5",
"SCRIPT_NAME"=>"",
"HTTP_VERSION"=>"HTTP/1.1",
"HTTP_X_FORWARDED_SERVER"=>"127.0.0.1",
"HTTP_X_FORWARDED_PROTO"=>"https",
"REQUEST_URI"=>"/signup/form/0",
"SERVER_PORT"=>"80",
"HTTP_X_FORWARDED_FOR"=>"127.0.0.1",
"HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"REQUEST_METHOD"=>"GET",
"QUERY_STRING"=>"",
"GATEWAY_INTERFACE"=>"CGI/1.2",
"HTTP_CONNECTION"=>"Keep-Alive",
"HTTP_ACCEPT_ENCODING"=>"gzip,deflate"}, {"Location"=>"http://
127.0.0.1/signup/form/0",
"X-Content-Digest"=>"531b3a921cf45cc6ed54e6da8f19b0c12dd4900e",
"Date"=>"Wed, 18 Nov 2009 18:38:28 GMT",
"Content-Type"=>"text/html; charset=utf-8",
"X-Runtime"=>"11",
"Content-Length"=>"96",
"Set-Cookie"=>"",
"Cache-Control"=>"no-cache, s-maxage=31536000",
"X-Status"=>"302"}]]

Notice that in the cached headers the "Cache-Control" is set to "no-
cache, s-maxage=31536000." It's my understanding that if a response
contains the "no-cache" directive that the response should not be
cached under any circumstances. So, why was this response cached?

There's a lot more to my story, but, I figured I'd start here because
it seems to me that this page should have never been cached in the
first place and I cannot get it to cache this page most of the time.

Thanks in advance,
Jason

Ryan Tomayko

unread,
Nov 22, 2009, 12:57:05 PM11/22/09
to rack-...@googlegroups.com
Apologies for the moderation delay. I've been away for email for a few days...
You'd think that given the name "no-cache", huh? It's actually a bit
more complicated. no-cache means: "don't *serve* this from the cache
without first revalidating it with the origin server." That means that
a cache can store the response and then make a conditional request
(e.g., using an If-Not-Modified or If-None-Match with a Last-Modified
or ETag validator) on the backend before serving to the client.

Relevant piece of RFC 2616:

http://tools.ietf.org/html/rfc2616#section-14.9.1

All that being said, it doesn't look like the cached response includes
a validator so there's really no point in storing it. There should be
no chance it will be served from cache.

> There's a lot more to my story, but, I figured I'd start here because
> it seems to me that this page should have never been cached in the
> first place and I cannot get it to cache this page most of the time.

Do tell.

Thanks,
Ryan
--
# tomayko.com/about
Reply all
Reply to author
Forward
0 new messages