Skip to content


add rack-cache.force-pass option #37

merged 2 commits into from

2 participants


I have a need to optionally pass-through rack-cache. I have added the ability to set the rack-cache.force-pass env variable that can be set by a previous rack app, which forces rack-cache to pass through.

@rtomayko rtomayko merged commit 6943584 into rtomayko:master

I'm kind of amazed there's not already some way to get that behavior. Can you tell me about the circumstances where you need this? I can think of a few cases but I'm curious as to what you ran into.


Thanks for merging this in.

There are 2 use cases that we have. First is testing: allowing a "secret" HTTP X-header or query variable to activate the force-pass variable. The second is to pass on specific versions of our application, for example, a "slow mobile" version which uses no javascript and therefore can't be cached when authenticated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 9, 2011
  1. @tekwiz
Commits on Sep 10, 2011
  1. @tekwiz
Showing with 18 additions and 1 deletion.
  1. +7 −0 doc/faq.markdown
  2. +1 −1 lib/rack/cache/context.rb
  3. +10 −0 test/context_test.rb
7 doc/faq.markdown
@@ -110,6 +110,13 @@ frameworks are based entirely on manual purge and do not support validation at
the cache level.
+<a class='hash' id='force-pass' href='#force-pass'>#</a>
+### Q: How do I bypass rack-cache on a per-request basis?
+Set the `rack-cache.force-pass` variable in the rack environment to `true`.
<a class='hash' id='efficient-validation' href='#efficient-validation'>#</a>
### Q: What does "Efficient Validation" mean?
2 lib/rack/cache/context.rb
@@ -61,7 +61,7 @@ def call!(env)
response =
if @request.get? || @request.head?
- if !@env['HTTP_EXPECT']
+ if !@env['HTTP_EXPECT'] and !@env['rack-cache.force-pass']
10 test/context_test.rb
@@ -15,6 +15,16 @@
response.headers.should.not.include 'Age'
+ it 'passes on rack-cache.force-pass' do
+ respond_with 200
+ get '/', {"rack-cache.force-pass" => true}
+ cache.trace.should == [:pass]
+ response.headers.should.not.include 'Age'
+ end
%w[post put delete].each do |request_method|
it "invalidates on #{request_method} requests" do
respond_with 200
Something went wrong with that request. Please try again.