mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #11785 from grosser/grosser/file-unless-exist
support :unless_exist for FileCache Conflicts: activesupport/CHANGELOG.md activesupport/test/caching_test.rb
This commit is contained in:
commit
f18cf8e488
3 changed files with 12 additions and 0 deletions
|
@ -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 @@ 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue