Skip to content

Commit

Permalink
Merge pull request #6252 from grosser/unless_exist_for_memory_store
Browse files Browse the repository at this point in the history
add unless_exist option to memory store
  • Loading branch information
josevalim committed May 10, 2012
2 parents dd9ea8d + b5005b6 commit 4142067
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions activesupport/lib/active_support/cache/memory_store.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/caching_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4142067

Please sign in to comment.