aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-12-12 14:04:21 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-12-12 14:04:21 -0200
commit415d1e10e395b91c83bdb7d692ffd93c5ca73814 (patch)
tree3ebedf513604366978cdda54a1ecbb7a48f2648c /activesupport
parent1454f2c20a988e320f4f9466caae83b59f959c3b (diff)
parent337a07b58927e08d993c1b0222e62e9ca116deae (diff)
downloadrails-415d1e10e395b91c83bdb7d692ffd93c5ca73814.tar.gz
rails-415d1e10e395b91c83bdb7d692ffd93c5ca73814.tar.bz2
rails-415d1e10e395b91c83bdb7d692ffd93c5ca73814.zip
Merge pull request #13268 from aayushkhandelwal11/master
Moving the common code of increment and decrement of cache file store in...
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb38
1 files changed, 16 insertions, 22 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index 5795d86a42..d8d910acb6 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -43,33 +43,13 @@ module ActiveSupport
# Increments an already existing integer value that is stored in the cache.
# If the key is not found nothing is done.
def increment(name, amount = 1, options = nil)
- file_name = key_file_path(namespaced_key(name, options))
- lock_file(file_name) do
- options = merged_options(options)
- if num = read(name, options)
- num = num.to_i + amount
- write(name, num, options)
- num
- else
- nil
- end
- end
+ modify_value(name, amount, options)
end
# Decrements an already existing integer value that is stored in the cache.
# If the key is not found nothing is done.
def decrement(name, amount = 1, options = nil)
- file_name = key_file_path(namespaced_key(name, options))
- lock_file(file_name) do
- options = merged_options(options)
- if num = read(name, options)
- num = num.to_i - amount
- write(name, num, options)
- num
- else
- nil
- end
- end
+ modify_value(name, amount*-1, options)
end
def delete_matched(matcher, options = nil)
@@ -184,6 +164,20 @@ module ActiveSupport
end
end
end
+
+ #This method performs an action(passed) already existing integer value that is stored in the cache
+ # If the key is not found nothing is done
+ def modify_value(name, amount, options)
+ file_name = key_file_path(namespaced_key(name, options))
+ lock_file(file_name) do
+ options = merged_options(options)
+ if num = read(name, options)
+ num = num.to_i + amount
+ write(name, num, options)
+ num
+ end
+ end
+ end
end
end
end