Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add unless_exist option to memory store

  • Loading branch information...
commit b5005b6259144eeea5b903d659f54bd8a0343d25 1 parent dd9ea8d
Michael Grosser authored
1  activesupport/lib/active_support/cache/memory_store.rb
@@ -137,6 +137,7 @@ def read_entry(key, options) # :nodoc:
137 137
         def write_entry(key, entry, options) # :nodoc:
138 138
           synchronize do
139 139
             old_entry = @data[key]
  140
+            return false if @data.key?(key) && options[:unless_exist]
140 141
             @cache_size -= old_entry.size if old_entry
141 142
             @cache_size += entry.size
142 143
             @key_access[key] = Time.now.to_f
7  activesupport/test/caching_test.rb
@@ -684,6 +684,13 @@ def @cache.delete_entry (*args)
684 684
     assert @cache.exist?(2)
685 685
     assert !@cache.exist?(1)
686 686
   end
  687
+
  688
+  def test_write_with_unless_exist
  689
+    assert_equal true, @cache.write(1, "aaaaaaaaaa")
  690
+    assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true)
  691
+    @cache.write(1, nil)
  692
+    assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true)
  693
+  end
687 694
 end
688 695
 
689 696
 uses_memcached 'memcached backed store' do

0 notes on commit b5005b6

Please sign in to comment.
Something went wrong with that request. Please try again.