diff options
author | Aayush khandelwal <aayush.khandelwal@vinsol.com> | 2013-12-11 16:31:20 +0530 |
---|---|---|
committer | Aayush khandelwal <aayush.khandelwal@vinsol.com> | 2013-12-12 18:39:39 +0530 |
commit | 337a07b58927e08d993c1b0222e62e9ca116deae (patch) | |
tree | deb09c56e6f2e88e0706f2ea6387dcf2806ed19f /activesupport/lib | |
parent | 11c0ef58a6cd278fc6b5d81a7724d9bcdb47f623 (diff) | |
download | rails-337a07b58927e08d993c1b0222e62e9ca116deae.tar.gz rails-337a07b58927e08d993c1b0222e62e9ca116deae.tar.bz2 rails-337a07b58927e08d993c1b0222e62e9ca116deae.zip |
Moving the common code of increment and decrement of cache file store into seprate function
Removing the double checking for the value of id
simplifying code for checking conditional code for key
Removing the default values for parameters
removing reduntant code and asiigning value of id in local variable
removing wrongly added line break[ci ckip]
reverting code
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 38 |
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 5cd6065077..4d0d0ff622 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 |