module FastCache; end # Utilities and support require 'fastcache/util/maybe' # Bucketing algorithms require 'fastcache/bucket/consistent' require 'fastcache/bucket/modulus' # Key hashing algorithms require 'fastcache/hash/crc32' require 'fastcache/hash/md5' require 'fastcache/hash/sha1' # Key routers # TODO: Check for ruby-ketama require 'fastcache/routing/basic_router' # Networking and protocol support code require 'fastcache/memcache' # Interfaces require 'fastcache/interface/connection' require 'fastcache/interface/marshaled' require 'fastcache/interface/dictionary' require 'fastcache/interface/evaluator' class << FastCache def connect(node_list = 'localhost:11211', opts = {}) opts = { :name => 'default', :type => 'raw' }.merge(opts) connections[opts[:name]].close_all_connections if connections[opts[:name]] node_list = node_list.split(',') if String === node_list nodes = node_list.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 def connection(name = 'default') connections[name] or raise ArgumentError, "Invalid connection name #{name.inspect}" end private def connections @connections ||= {} end end