Skip to content

Commit

Permalink
Bring MemCacheStore and CompressedMemCacheStore inline with expected …
Browse files Browse the repository at this point in the history
…counter manipulation semantics.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
dougbarth authored and NZKoz committed Oct 17, 2008
1 parent c3d6205 commit 4b63c27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Expand Up @@ -3,12 +3,17 @@ module Cache
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
Expand Down
3 changes: 3 additions & 0 deletions activesupport/lib/active_support/cache/mem_cache_store.rb
Expand Up @@ -34,6 +34,9 @@ def read(key, options = nil)
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
Expand Down
10 changes: 0 additions & 10 deletions activesupport/test/caching_test.rb
Expand Up @@ -159,11 +159,6 @@ def test_store_objects_should_be_immutable
@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
Expand All @@ -173,9 +168,4 @@ def setup
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

0 comments on commit 4b63c27

Please sign in to comment.