Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use duck typing to also allow MemCache-like object when initializing …

…a MemCacheStore

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 542d6a0abd712be8892ef044ef40fe7bbc9631a9 1 parent 2a65772
@brynary brynary authored jeremy committed
View
2  activesupport/CHANGELOG
@@ -1,6 +1,6 @@
*2.3.3 (pending)*
-* 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]
*2.3.2 [Final] (March 15, 2009)*
View
2  activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -39,7 +39,7 @@ def self.build_mem_cache(*addresses)
# 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)
View
6 activesupport/test/caching_test.rb
@@ -32,6 +32,12 @@ def test_mem_cache_fragment_cache_store_with_given_mem_cache
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'
Please sign in to comment.
Something went wrong with that request. Please try again.