From f4dbac9280fca7bf8a75d0dd85a16c5713e175f2 Mon Sep 17 00:00:00 2001 From: Doug Barth Date: Thu, 9 Oct 2008 10:47:32 -0500 Subject: [PATCH] Bring MemCacheStore and CompressedMemCacheStore inline with expected counter manipulation semantics. --- .../cache/compressed_mem_cache_store.rb | 9 +++++++-- .../lib/active_support/cache/mem_cache_store.rb | 1 + activesupport/test/caching_test.rb | 10 ---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb b/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb index 0bff6cf..d87eb17 100644 --- a/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb @@ -3,12 +3,17 @@ module ActiveSupport class CompressedMemCacheStore < MemCacheStore def read(name, options = nil) if value = super(name, (options || {}).merge(:raw => true)) - Marshal.load(ActiveSupport::Gzip.decompress(value)) + if raw?(options) + value + else + Marshal.load(ActiveSupport::Gzip.decompress(value)) + end end end def write(name, value, options = nil) - super(name, ActiveSupport::Gzip.compress(Marshal.dump(value)), (options || {}).merge(:raw => true)) + value = ActiveSupport::Gzip.compress(Marshal.dump(value)) unless raw?(options) + super(name, value, (options || {}).merge(:raw => true)) end end end diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 58958dc..ae468a6 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -34,6 +34,7 @@ module ActiveSupport def write(key, value, options = nil) super method = options && options[:unless_exist] ? :add : :set + value = value.to_s if raw?(options) response = @data.send(method, key, value, expires_in(options), raw?(options)) response == Response::STORED rescue MemCache::MemCacheError => e diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index e2da279..88c6d6c 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -159,11 +159,6 @@ class MemCacheStoreTest < Test::Unit::TestCase @cache.read('foo').gsub!(/.*/, 'baz') assert_equal 'bar', @cache.read('foo') end - - # Disabling increment and decrement tests until issues can be addressed in the - # upstream codebase. - def test_increment; end - def test_decrement; end end class CompressedMemCacheStore < Test::Unit::TestCase @@ -173,9 +168,4 @@ class CompressedMemCacheStore < Test::Unit::TestCase end include CacheStoreBehavior - - # Disabling increment and decrement tests until issues can be addressed in the - # upstream codebase. - def test_increment; end - def test_decrement; end end -- 1.5.6.1