Permalink
Browse files

Merge pull request #11785 from grosser/grosser/file-unless-exist

support :unless_exist for FileCache

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/test/caching_test.rb
  • Loading branch information...
rafaelfranca committed Oct 28, 2013
2 parents f78c5fb + c17bd74 commit f18cf8e4884529f28d19f118abd0b46c99bd8cfa
@@ -1,3 +1,7 @@
+* Support :unless_exist in FileStore
+
+ *Michael Grosser*
+
* Fix `slice!` deleting the default value of the hash.
*Antonio Santos*
@@ -97,6 +97,7 @@ def read_entry(key, options)
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
@@ -721,6 +721,13 @@ def test_cleanup_removes_all_expired_entries
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

0 comments on commit f18cf8e

Please sign in to comment.