aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache/mem_cache_store.rb
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-19 10:24:26 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2009-05-19 10:54:56 -0700
commite2ed1a1ca4f2dbfb9eb2c31fd1ddd45562afef25 (patch)
tree95c0380f42913615362fc9468b0ea6bca38a8b7d /activesupport/lib/active_support/cache/mem_cache_store.rb
parent6dc3a6a954b742ac7160593f94962b9b93a2ce25 (diff)
downloadrails-e2ed1a1ca4f2dbfb9eb2c31fd1ddd45562afef25.tar.gz
rails-e2ed1a1ca4f2dbfb9eb2c31fd1ddd45562afef25.tar.bz2
rails-e2ed1a1ca4f2dbfb9eb2c31fd1ddd45562afef25.zip
Allow MemCacheStore to be initialized with a MemCache object instead of addresses and options
Diffstat (limited to 'activesupport/lib/active_support/cache/mem_cache_store.rb')
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index 90b7526fe1..ab8eb72096 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -23,7 +23,12 @@ module ActiveSupport
DELETED = "DELETED\r\n"
end
- attr_reader :addresses
+ def self.build_mem_cache(*addresses)
+ addresses = addresses.flatten
+ options = addresses.extract_options!
+ addresses = ["localhost"] if addresses.empty?
+ MemCache.new(addresses, options)
+ end
# Creates a new MemCacheStore object, with the given memcached server
# addresses. Each address is either a host name, or a host-with-port string
@@ -34,11 +39,11 @@ module ActiveSupport
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
def initialize(*addresses)
- addresses = addresses.flatten
- options = addresses.extract_options!
- addresses = ["localhost"] if addresses.empty?
- @addresses = addresses
- @data = MemCache.new(addresses, options)
+ if addresses.first.is_a?(MemCache)
+ @data = addresses.first
+ else
+ @data = self.class.build_mem_cache(*addresses)
+ end
extend Strategy::LocalCache
end