aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-28 19:09:22 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-28 19:09:22 -0200
commitf18cf8e4884529f28d19f118abd0b46c99bd8cfa (patch)
treeda0bdb7f4888b51cac17e3d31029c71ff52b5797 /activesupport
parentf78c5fbb96b507fb80405c25cfce12136f9d45cd (diff)
parentc17bd7476abb0bade3c27e652b1d56548d0ee4ae (diff)
downloadrails-f18cf8e4884529f28d19f118abd0b46c99bd8cfa.tar.gz
rails-f18cf8e4884529f28d19f118abd0b46c99bd8cfa.tar.bz2
rails-f18cf8e4884529f28d19f118abd0b46c99bd8cfa.zip
Merge pull request #11785 from grosser/grosser/file-unless-exist
support :unless_exist for FileCache Conflicts: activesupport/CHANGELOG.md activesupport/test/caching_test.rb
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb1
-rw-r--r--activesupport/test/caching_test.rb7
3 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index cae4ee7fde..25667af101 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Support :unless_exist in FileStore
+
+ *Michael Grosser*
+
* Fix `slice!` deleting the default value of the hash.
*Antonio Santos*
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index 10d39463ec..5cd6065077 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -97,6 +97,7 @@ module ActiveSupport
def write_entry(key, entry, options)
file_name = key_file_path(key)
+ return false if options[:unless_exist] && File.exist?(file_name)
ensure_cache_path(File.dirname(file_name))
File.atomic_write(file_name, cache_path) {|f| Marshal.dump(entry, f)}
true
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 16d087ab9d..51007402a1 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -721,6 +721,13 @@ class FileStoreTest < ActiveSupport::TestCase
assert @cache.exist?('baz')
assert @cache.exist?('quux')
end
+
+ def test_write_with_unless_exist
+ assert_equal true, @cache.write(1, "aaaaaaaaaa")
+ assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
+ @cache.write(1, nil)
+ assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
+ end
end
class MemoryStoreTest < ActiveSupport::TestCase