diff options
author | wangjohn <wangjohn@mit.edu> | 2013-04-17 17:29:58 -0400 |
---|---|---|
committer | wangjohn <wangjohn@mit.edu> | 2013-04-17 18:50:24 -0400 |
commit | fdb3e7341157f618f65683d08e1a55981a5d91d2 (patch) | |
tree | 5d425cea250477e8389000a2b304d13ac1b150e7 /activesupport/lib/active_support/cache/strategy | |
parent | e12f39f37407975f61e35dbbad583bc825ef4df8 (diff) | |
download | rails-fdb3e7341157f618f65683d08e1a55981a5d91d2.tar.gz rails-fdb3e7341157f618f65683d08e1a55981a5d91d2.tar.bz2 rails-fdb3e7341157f618f65683d08e1a55981a5d91d2.zip |
The increment and decrement commands in the local cache are exactly the
same, so their logic is being refactored.
Diffstat (limited to 'activesupport/lib/active_support/cache/strategy')
-rw-r--r-- | activesupport/lib/active_support/cache/strategy/local_cache.rb | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 392c9283d7..fb42c4a41e 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -106,29 +106,13 @@ module ActiveSupport def increment(name, amount = 1, options = nil) # :nodoc: value = bypass_local_cache{super} - if local_cache - local_cache.mute do - if value - local_cache.write(name, value, options) - else - local_cache.delete(name, options) - end - end - end + increment_or_decrement(value, name, amount, options) value end def decrement(name, amount = 1, options = nil) # :nodoc: value = bypass_local_cache{super} - if local_cache - local_cache.mute do - if value - local_cache.write(name, value, options) - else - local_cache.delete(name, options) - end - end - end + increment_or_decrement(value, name, amount, options) value end @@ -157,6 +141,18 @@ module ActiveSupport end private + def increment_or_decrement(value, name, amount, options) + if local_cache + local_cache.mute do + if value + local_cache.write(name, value, options) + else + local_cache.delete(name, options) + end + end + end + end + def local_cache_key @local_cache_key ||= "#{self.class.name.underscore}_local_cache_#{object_id}".gsub(/[\/-]/, '_').to_sym end |