diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2015-11-10 15:20:18 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2015-11-10 15:20:18 -0200 |
commit | 5388464af6ec229ddf3a1040cd7466f45370cedd (patch) | |
tree | 051f6e6ef774f805716955921c68a4772d98eea9 | |
parent | 6c3db3652faaa54e4e0b052e4042717c73f0d2f8 (diff) | |
parent | cfc6d8356f71357d6a5e9e978ea246e95bc7bf0f (diff) | |
download | rails-5388464af6ec229ddf3a1040cd7466f45370cedd.tar.gz rails-5388464af6ec229ddf3a1040cd7466f45370cedd.tar.bz2 rails-5388464af6ec229ddf3a1040cd7466f45370cedd.zip |
Merge pull request #22216 from grosser/grosser/fast-ret
fast and consistent return when local_cache does not exist
-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 |