From 4b63c2700ffc5c646af0e728d4ec2fcb6770671b Mon Sep 17 00:00:00 2001 From: Doug Barth Date: Thu, 9 Oct 2008 10:47:32 -0500 Subject: Bring MemCacheStore and CompressedMemCacheStore inline with expected counter manipulation semantics. Signed-off-by: Michael Koziarski --- .../lib/active_support/cache/compressed_mem_cache_store.rb | 9 +++++++-- activesupport/lib/active_support/cache/mem_cache_store.rb | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') 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 0bff6cf9ad..d87eb17337 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 58958dccef..5531c30b7f 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -34,6 +34,9 @@ module ActiveSupport def write(key, value, options = nil) super method = options && options[:unless_exist] ? :add : :set + # memcache-client will break the connection if you send it an integer + # in raw mode, so we convert it to a string to be sure it continues working. + 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 -- cgit v1.2.3