mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
add unless_exist option to memory store
This commit is contained in:
parent
dd9ea8d4de
commit
b5005b6259
2 changed files with 8 additions and 0 deletions
|
@ -137,6 +137,7 @@ module ActiveSupport
|
|||
def write_entry(key, entry, options) # :nodoc:
|
||||
synchronize do
|
||||
old_entry = @data[key]
|
||||
return false if @data.key?(key) && options[:unless_exist]
|
||||
@cache_size -= old_entry.size if old_entry
|
||||
@cache_size += entry.size
|
||||
@key_access[key] = Time.now.to_f
|
||||
|
|
|
@ -684,6 +684,13 @@ class MemoryStoreTest < ActiveSupport::TestCase
|
|||
assert @cache.exist?(2)
|
||||
assert !@cache.exist?(1)
|
||||
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
|
||||
|
||||
uses_memcached 'memcached backed store' do
|
||||
|
|
Loading…
Reference in a new issue