diff options
author | Michael Grosser <michael@grosser.it> | 2015-11-07 12:27:39 -0800 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-11 07:08:20 +0100 |
commit | f87774bb8b3249dbcd1f16035874f9e583df82d0 (patch) | |
tree | 535044dce24b458675bb6beb53738c54c50ce2b8 /activesupport/lib/active_support | |
parent | 7edc8d9600465577c29fd36de2cc57392f56616d (diff) | |
download | rails-f87774bb8b3249dbcd1f16035874f9e583df82d0.tar.gz rails-f87774bb8b3249dbcd1f16035874f9e583df82d0.tar.bz2 rails-f87774bb8b3249dbcd1f16035874f9e583df82d0.zip |
fast and consistent return when local_cache does not exist
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/cache/strategy/local_cache.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index d521061004..fa007aad56 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -79,22 +79,26 @@ module ActiveSupport end def clear(options = nil) # :nodoc: - local_cache.clear(options) if local_cache + return super unless cache = local_cache + cache.clear(options) super end def cleanup(options = nil) # :nodoc: - local_cache.clear(options) if local_cache + return super unless cache = local_cache + cache.clear(options) super end def increment(name, amount = 1, options = nil) # :nodoc: + return super unless local_cache value = bypass_local_cache{super} set_cache_value(value, name, amount, options) value end def decrement(name, amount = 1, options = nil) # :nodoc: + return super unless local_cache value = bypass_local_cache{super} set_cache_value(value, name, amount, options) value @@ -120,13 +124,12 @@ module ActiveSupport end def set_cache_value(value, name, amount, options) # :nodoc: - if local_cache - local_cache.mute do - if value - local_cache.write(name, value, options) - else - local_cache.delete(name, options) - end + cache = local_cache + cache.mute do + if value + cache.write(name, value, options) + else + cache.delete(name, options) end end end |