class method
self.new
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.new(*args)
Accepts a list of servers and a list of opts. servers may be omitted. See servers= for acceptable server list arguments.
Valid options for opts are:
[:namespace] Prepends this value to all keys added or retrieved.
[:readonly] Raises an exception on cache writes when true.
[:multithread] Wraps cache access in a Mutex for thread safety. Defaults to true.
[:failover] Should the client try to failover to another server if the
first server is down? Defaults to true.
[:timeout] Time to use as the socket read timeout. Defaults to 0.5 sec,
set to nil to disable timeouts (this is a major performance penalty in Ruby 1.8,
"gem install SystemTimer' to remove most of the penalty).
[:logger] Logger to use for info/debug output, defaults to nil
[:no_reply] Don't bother looking for a reply for write operations (i.e. they
become 'fire and forget'), memcached 1.2.5 and later only, speeds up
set/add/delete/incr/decr significantly.
Other options are ignored.
Parameters
-
argsrest
Source
# File activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb, line 102
def initialize(*args)
servers = []
opts = {}
case args.length
when 0 then # NOP
when 1 then
arg = args.shift
case arg
when Hash then opts = arg
when Array then servers = arg
when String then servers = [arg]
else raise ArgumentError, 'first argument must be Array, Hash or String'
end
when 2 then
servers, opts = args
else
raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
end
opts = DEFAULT_OPTIONS.merge opts
@namespace = opts[:namespace]
@readonly = opts[:readonly]
@multithread = opts[:multithread]
@timeout = opts[:timeout]
@failover = opts[:failover]
@logger = opts[:logger]
@no_reply = opts[:no_reply]
@mutex = Mutex.new if @multithread
logger.info { "memcache-client #{VERSION} #{Array(servers).inspect}" } if logger
Thread.current[:memcache_client] = self.object_id if !@multithread
self.servers = servers
end
Defined in activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb line 102
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in MemCache