提交 88c3fd1e 编写于 作者: G Guillermo Iguaran

Merge pull request #13583 from arthurnn/mem_cache_store_fix

mem_cache_store requires dalli, so only accept dalli/client
* MemCacheStore should only accept a Dalli::Client, or create one.
*arthurnn*
* Don't lazy load the `tzinfo` library as it causes problems on Windows.
Fixes #13553
......
......@@ -41,17 +41,15 @@ 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)
unless [String, Dalli::Client, NilClass].include?(addresses.first.class)
raise ArgumentError, "First argument must be an empty array, an array of hosts or a Dalli::Client instance."
end
if addresses.first.is_a?(Dalli::Client)
@data = addresses.first
else
mem_cache_options = options.dup
......
......@@ -110,12 +110,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
def test_mem_cache_fragment_cache_store_with_not_dalli_client
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)
assert_raises(ArgumentError) do
ActiveSupport::Cache.lookup_store :mem_cache_store, memcache
end
end
def test_mem_cache_fragment_cache_store_with_multiple_servers
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册