Browse files

allow IMS/INM requests through to backend on miss, fixes #24

Prior to this change, rack-cache would always strip any
If-None-Match and/or If-Modified-Since headers from the request
before passing along to the backend in an attempt to retrieve a
response to put in the cache (304 responses are not currently
cacheable). This approach falls down when the response includes a
'Cache-Control: private' header (Rails default) because the response
cannot be cached but will also never allow for client initiated

The downside to this change is that the cache will fill in more
slowly when clients make conditional requests for public resources;
it won't fill in until a non-conditional request is received. The
upside is that validation works for non-cacheable private responses.
  • Loading branch information...
1 parent 9cf8c0e commit f9498239eb856b8061fe29e4dd564c4c910c54c3 @rtomayko committed Sep 18, 2011
Showing with 3 additions and 5 deletions.
  1. +3 −5 lib/rack/cache/context.rb
@@ -231,15 +231,13 @@ def validate(entry)
# The cache missed or a reload is required. Forward the request to the
- # backend and determine whether the response should be stored.
+ # backend and determine whether the response should be stored. This allows
+ # conditional / validation requests through to the backend but performs no
+ # caching of the response when the backend returns a 304.
def fetch
# send no head requests because we want content
- # avoid that the backend sends no content
- @env.delete('HTTP_IF_MODIFIED_SINCE')
- @env.delete('HTTP_IF_NONE_MATCH')
response = forward
# Mark the response as explicitly private if any of the private

0 comments on commit f949823

Please sign in to comment.