Permalink
Browse files

The increment and decrement commands in the local cache are exactly the

same, so their logic is being refactored.
  • Loading branch information...
wangjohn committed Apr 17, 2013
1 parent e12f39f commit fdb3e7341157f618f65683d08e1a55981a5d91d2
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

3 comments on commit fdb3e73

@tamird

This comment has been minimized.

Show comment
Hide comment
@tamird

tamird Apr 18, 2013

Contributor

If they're exactly the same (and they seem to be), why not just alias one to the other? additional indirection is probably not the best thing.

Contributor

tamird replied Apr 18, 2013

If they're exactly the same (and they seem to be), why not just alias one to the other? additional indirection is probably not the best thing.

@dmathieu

This comment has been minimized.

Show comment
Hide comment
@dmathieu

dmathieu Apr 18, 2013

Contributor

Because they're not exactly the same, as they do opposite things. So they can't be aliased.

Contributor

dmathieu replied Apr 18, 2013

Because they're not exactly the same, as they do opposite things. So they can't be aliased.

@tamird

This comment has been minimized.

Show comment
Hide comment
@tamird

tamird Apr 18, 2013

Contributor

@dmathieu actually, they are exatly the same, despite what the names indicate.

Contributor

tamird replied Apr 18, 2013

@dmathieu actually, they are exatly the same, despite what the names indicate.

Please sign in to comment.