aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-19 19:51:38 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2009-05-19 16:58:04 -0700
commit36058f45040b5559fd8f6a44a17ead27a6b3d2f7 (patch)
treeeb931d92074b7bb792330431db81114409a5d1de /activesupport
parentd8fffe7b23acce42bc3941d7bba47e07a66aed67 (diff)
downloadrails-36058f45040b5559fd8f6a44a17ead27a6b3d2f7.tar.gz
rails-36058f45040b5559fd8f6a44a17ead27a6b3d2f7.tar.bz2
rails-36058f45040b5559fd8f6a44a17ead27a6b3d2f7.zip
Use duck typing to also allow MemCache-like object when initializing a MemCacheStore
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb2
-rw-r--r--activesupport/test/caching_test.rb6
3 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 6551be01f9..27d26b2ba5 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,6 +1,6 @@
*Edge*
-* Allow MemCacheStore to be initialized with a MemCache object instead of addresses and options [Bryan Helmkamp]
+* Allow MemCacheStore to be initialized with a MemCache-like object instead of addresses and options [Bryan Helmkamp]
* Change spelling of Kyev timezone to Kyiv #2613 [Alexander Dymo]
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index ab8eb72096..38b3409ca6 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -39,7 +39,7 @@ module ActiveSupport
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
def initialize(*addresses)
- if addresses.first.is_a?(MemCache)
+ if addresses.first.respond_to?(:get)
@data = addresses.first
else
@data = self.class.build_mem_cache(*addresses)
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index ad19dcfd09..bd237a5c8e 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -27,6 +27,12 @@ class CacheStoreSettingTest < ActiveSupport::TestCase
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
end
+ def test_mem_cache_fragment_cache_store_with_given_mem_cache_like_object
+ MemCache.expects(:new).never
+ store = ActiveSupport::Cache.lookup_store :mem_cache_store, stub("memcache", :get => true)
+ assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
+ end
+
def test_mem_cache_fragment_cache_store_with_multiple_servers
MemCache.expects(:new).with(%w[localhost 192.168.1.1], {})
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'