diff options
author | José Valim <jose.valim@gmail.com> | 2012-05-10 08:57:59 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-05-10 08:57:59 -0700 |
commit | 41420675fd10add560353eaa4e3a3f6518df864e (patch) | |
tree | 5448e7da507620364a7911cec955a429ce7e7247 /activesupport | |
parent | dd9ea8d4dededdad2c6de23260a24b2835fb2fbd (diff) | |
parent | b5005b6259144eeea5b903d659f54bd8a0343d25 (diff) | |
download | rails-41420675fd10add560353eaa4e3a3f6518df864e.tar.gz rails-41420675fd10add560353eaa4e3a3f6518df864e.tar.bz2 rails-41420675fd10add560353eaa4e3a3f6518df864e.zip |
Merge pull request #6252 from grosser/unless_exist_for_memory_store
add unless_exist option to memory store
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/cache/memory_store.rb | 1 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index b15bb42c88..7fd5e3b53d 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -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 diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index bb9ce23276..d62b782e2d 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -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 |