提交 c17bd747 编写于 作者: G grosser

support :unless_exist for FileCache

上级 f90aa722
* Support :unless_exist in FileStore
*Michael Grosser*
* Ensure that autoloaded constants in all-caps nestings are marked as
autoloaded.
......
......@@ -96,6 +96,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
......
......@@ -709,6 +709,13 @@ def test_log_exception_when_cache_read_fails
@cache.send(:read_entry, "winston", {})
assert @buffer.string.present?
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册