aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache/strategy/local_cache.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-01-08 15:48:19 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-01-08 15:48:19 -0800
commite176353b71607f6fd57b327ba3ca12712639ce00 (patch)
tree18dc6b94196730243054d0ddd2c5e70cfe526110 /activesupport/lib/active_support/cache/strategy/local_cache.rb
parent2875b4a66e38e4333da887a4afbed33358999298 (diff)
downloadrails-e176353b71607f6fd57b327ba3ca12712639ce00.tar.gz
rails-e176353b71607f6fd57b327ba3ca12712639ce00.tar.bz2
rails-e176353b71607f6fd57b327ba3ca12712639ce00.zip
clear cache on body close so that cache remains during rendering
fixes #13547 The body may use the local cache during rendering. `call`ing the app doesn't mean that rendering is finished, so we need to wait until `close` is called on the body.
Diffstat (limited to 'activesupport/lib/active_support/cache/strategy/local_cache.rb')
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb
index cea7eee924..4eaf57f385 100644
--- a/activesupport/lib/active_support/cache/strategy/local_cache.rb
+++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/string/inflections'
+require 'rack/body_proxy'
module ActiveSupport
module Cache
@@ -83,9 +84,14 @@ module ActiveSupport
def call(env)
LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
- @app.call(env)
- ensure
+ response = @app.call(env)
+ response[2] = ::Rack::BodyProxy.new(response[2]) do
+ LocalCacheRegistry.set_cache_for(local_cache_key, nil)
+ end
+ response
+ rescue Exception
LocalCacheRegistry.set_cache_for(local_cache_key, nil)
+ raise
end
end