From ae8b25bde4bd084288427c8da74f2d98d3098fea Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 25 Jan 2010 23:52:47 +0700 Subject: [PATCH] Modify CompressedMemCacheStore to use read method, since read_multi requires value to be marshaled. Also add some documentation to read_multi --- activesupport/lib/active_support/cache.rb | 3 +++ .../cache/compressed_mem_cache_store.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index c80a770..59fe3a1 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -240,6 +240,9 @@ module ActiveSupport end end + # Fetches data from the cache, using the given keys. This method actually + # calls +read+ multiple times, so it won't give you any performance gain + # unless you're using MemCacheStore. def read_multi(*keys) keys.flatten.inject({}) do |results, key| if (value = read(key)) 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 d2370d7..41d5b6f 100644 --- a/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb @@ -13,6 +13,18 @@ module ActiveSupport end end + # This +read_multi+ method will actually call +read+, since library's +get_multi+ + # method requires data to be marshal. However, CompressedMemCacheStore stores the + # raw, unmarshaed value to Memcached server. + def read_multi(*keys) + keys.flatten.inject({}) do |results, key| + if (value = read(key)) + results[key] = value + end + results + end + end + def write(name, value, options = nil) value = ActiveSupport::Gzip.compress(Marshal.dump(value)) unless raw?(options) super(name, value, (options || {}).merge(:raw => true)) -- 1.6.4.2