From 06c00cccd3ac8d5560896e499670e00f3cbc269f Mon Sep 17 00:00:00 2001 From: Joe Van Dyk Date: Mon, 2 Feb 2009 16:43:14 -0800 Subject: [PATCH] Add ability to get multiple memcached keys at the same time (via MemCacheStore#read_multi). --- .../lib/active_support/cache/mem_cache_store.rb | 5 +++++ activesupport/test/caching_test.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) create mode 100644 activesupport/memcached_get_multi.diff diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 4d8e1fd..90b7526 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -43,6 +43,11 @@ module ActiveSupport extend Strategy::LocalCache end + # Reads multiple keys from the cache. + def read_multi(*keys) + @data.get_multi keys + end + def read(key, options = nil) # :nodoc: super @data.get(key, raw?(options)) diff --git a/activesupport/memcached_get_multi.diff b/activesupport/memcached_get_multi.diff new file mode 100644 index 0000000..e69de29 diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 4e212f1..5b2527b 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -256,6 +256,15 @@ uses_memcached 'memcached backed store' do end end + def test_multi_get + @cache.with_local_cache do + @cache.write('foo', 1) + @cache.write('goo', 2) + result = @cache.read_multi('foo', 'goo') + assert_equal({'foo' => 1, 'goo' => 2}, result) + end + end + def test_middleware app = lambda { |env| result = @cache.write('foo', 'bar') -- 1.5.4.3