Sha256: 057382f78998ab05cb2ac6b985e73e0b03b6b6f23ea6a41ecbb4b362a10b30ec

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
binary42-fastcache-0.3 lib/fastcache.rb