Browse files

mem_cache_store requires dalli, so only accept dalli/client

:mem_cache_store require dalli, rescue Dalli exceptions, and follow Dalli API.
Memcached gem, for instance, doesnt work anymore, as the API are different.

As we already require one client, we should make sure that client works, and not accept others, and if someone wants to use another memcache client they can write their own store adapter.
  • Loading branch information...
1 parent f89266a commit 98458eea425d15ebadf366d8b55fc89c1913d146 @arthurnn arthurnn committed Jan 3, 2014
Showing with 1 addition and 14 deletions.
  1. +1 −6 activesupport/lib/active_support/cache/mem_cache_store.rb
  2. +0 −8 activesupport/test/caching_test.rb
View
7 activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -41,17 +41,12 @@ def self.build_mem_cache(*addresses)
#
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
- #
- # Instead of addresses one can pass in a MemCache-like object. For example:
- #
- # require 'memcached' # gem install memcached; uses C bindings to libmemcached
- # ActiveSupport::Cache::MemCacheStore.new(Memcached::Rails.new("localhost:11211"))
def initialize(*addresses)
addresses = addresses.flatten
options = addresses.extract_options!
super(options)
- if addresses.first.respond_to?(:get)
+ if addresses.first.is_a?(Dalli::Client)
@data = addresses.first
else
mem_cache_options = options.dup
View
8 activesupport/test/caching_test.rb
@@ -110,14 +110,6 @@ 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
- Dalli::Client.expects(:new).never
- memcache = Object.new
- def memcache.get() true end
- store = ActiveSupport::Cache.lookup_store :mem_cache_store, memcache
- assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
- end
-
def test_mem_cache_fragment_cache_store_with_multiple_servers
Dalli::Client.expects(:new).with(%w[localhost 192.168.1.1], {})
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'

0 comments on commit 98458ee

Please sign in to comment.