Permalink
Browse files

Merge pull request #10255 from wangjohn/increment_or_decrement_refact…

…oring_in_local_cache

Refactoring increment and decrement in local cache
  • Loading branch information...
2 parents e12f39f + fdb3e73 commit 1c9136ddd2003923edb94c85447ab9272131794a @carlosantoniodasilva carlosantoniodasilva committed Apr 17, 2013
Showing with 14 additions and 18 deletions.
  1. +14 −18 activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -106,29 +106,13 @@ def cleanup(options = nil) # :nodoc:
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 @@ def delete_entry(key, options) # :nodoc:
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

0 comments on commit 1c9136d

Please sign in to comment.