Permalink
Browse files

Merge pull request #10254 from wangjohn/refactoring_local_cache

Refactored the storage of a temporary version of the local cache.
  • Loading branch information...
2 parents 88150e8 + d8b2588 commit e12f39f37407975f61e35dbbad583bc825ef4df8 @carlosantoniodasilva carlosantoniodasilva committed Apr 17, 2013
Showing with 6 additions and 8 deletions.
  1. +6 −8 activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -58,13 +58,7 @@ def delete_entry(key, options)
# 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 @@ def local_cache
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)

0 comments on commit e12f39f

Please sign in to comment.