Sha256: c9144f9473d6cbb59912cba969e0bba7dd16cc2dc53fc7e4dec2dc320ba618e0

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 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/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.2 lib/fastcache.rb