diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-17 15:01:59 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-17 15:01:59 -0700 |
commit | e12f39f37407975f61e35dbbad583bc825ef4df8 (patch) | |
tree | 752222b6ef54984098f1a49472db52e3fd3013c3 /activesupport/lib/active_support | |
parent | 88150e862251c80076f0a4b9c1aef02b2bb096cf (diff) | |
parent | d8b25884b6b12c2da2a3af1a2095d6e8a9f014ff (diff) | |
download | rails-e12f39f37407975f61e35dbbad583bc825ef4df8.tar.gz rails-e12f39f37407975f61e35dbbad583bc825ef4df8.tar.bz2 rails-e12f39f37407975f61e35dbbad583bc825ef4df8.zip |
Merge pull request #10254 from wangjohn/refactoring_local_cache
Refactored the storage of a temporary version of the local cache.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/cache/strategy/local_cache.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 157053ee4d..392c9283d7 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -58,13 +58,7 @@ module ActiveSupport # Use a local cache for the duration of block. def with_local_cache - save_val = LocalCacheRegistry.cache_for(local_cache_key) - begin - LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new) - yield - ensure - LocalCacheRegistry.set_cache_for(local_cache_key, save_val) - end + use_temporary_local_cache(LocalStore.new) { yield } end #-- @@ -172,9 +166,13 @@ module ActiveSupport end def bypass_local_cache + use_temporary_local_cache(nil) { yield } + end + + def use_temporary_local_cache(temporary_cache) save_cache = LocalCacheRegistry.cache_for(local_cache_key) begin - LocalCacheRegistry.set_cache_for(local_cache_key, nil) + LocalCacheRegistry.set_cache_for(local_cache_key, temporary_cache) yield ensure LocalCacheRegistry.set_cache_for(local_cache_key, save_cache) |