Merge pull request #6252 from grosser/unless_exist_for_memory_store
add unless_exist option to memory store
This commit is contained in:
commit
41420675fd
@ -137,6 +137,7 @@ def read_entry(key, options) # :nodoc:
|
||||
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 @@ def @cache.delete_entry (*args)
|
||||
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 New Issue
Block a user