Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #13268 from aayushkhandelwal11/master

Moving the common code of increment and decrement of cache file store in...
  • Loading branch information...
commit 415d1e10e395b91c83bdb7d692ffd93c5ca73814 2 parents 1454f2c + 337a07b
@rafaelfranca rafaelfranca authored
Showing with 16 additions and 22 deletions.
  1. +16 −22 activesupport/lib/active_support/cache/file_store.rb
View
38 activesupport/lib/active_support/cache/file_store.rb
@@ -43,33 +43,13 @@ def cleanup(options = nil)
# 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 @@ def search_dir(dir, &callback)
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
Please sign in to comment.
Something went wrong with that request. Please try again.