Browse files

Merge pull request #6252 from grosser/unless_exist_for_memory_store

add unless_exist option to memory store
  • Loading branch information...
2 parents dd9ea8d + b5005b6 commit 41420675fd10add560353eaa4e3a3f6518df864e @josevalim josevalim committed May 10, 2012
Showing with 8 additions and 0 deletions.
  1. +1 −0 activesupport/lib/active_support/cache/memory_store.rb
  2. +7 −0 activesupport/test/caching_test.rb
View
1 activesupport/lib/active_support/cache/memory_store.rb
@@ -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
View
7 activesupport/test/caching_test.rb
@@ -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

0 comments on commit 4142067

Please sign in to comment.