static public Method

MemCache.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 exeception on cache writes when true.
[:multithread] Wraps cache access in a Mutex for thread safety.

Other options are ignored.

Source Code

# File active_support/vendor/memcache-client-1.5.0/memcache.rb, line 127
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]
  @mutex       = Mutex.new if @multithread
  @buckets     = []
  self.servers = servers
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.