Module: FastCache

Defined in:
lib/fastcache.rb,
lib/fastcache/memcache.rb

Defined Under Namespace

Modules: Memcache Classes: CRC32, Connection, ConsistentBucket, Dictionary, Evaluator, Maybe, ModulusBucket

Constant Summary collapse

MD5 =
OpenSSL::Digest::MD5
SHA1 =
OpenSSL::Digest::SHA1

Class Method Summary collapse

Class Method Details

.connect(node_list = 'localhost:11211', opts = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastcache.rb', line 29

def connect(node_list = 'localhost:11211', opts = {})
  opts = {
    :name => 'default',
    :type => 'raw'
  }.merge(opts)

  connections[opts[:name]].close if connections[opts[:name]]

  nodes = node_list.split(',').map {|node|
    host, port = *node.split(':')
    port ||= 80
    [host, port.to_i]
  }

  connections[opts[:name]] = case(opts[:type])
  when FastCache::Connection
    opts[:type].new(nodes, opts[:connection])
  when 'dictionary'
    FastCache::Dictionary.new(nodes, opts[:connection])
  when 'evaluator'
    FastCache::Evaluator.new(nodes, opts[:connection])
  when 'raw'
    FastCache::Connection.new(nodes, opts[:connection])
  else
    raise "Unknown connection type #{opts[:type]}"
  end
end

.connection(name = 'default') ⇒ Object



57
58
59
60
# File 'lib/fastcache.rb', line 57

def connection(name = 'default')
  connections[name] or raise ArgumentError,
    "Invalid connection name #{name.inspect}"
end