Class: FastCache::Connection

Inherits:
Object
  • Object
show all
Includes:
Memcache::Protocol
Defined in:
lib/fastcache/interface/connection.rb

Direct Known Subclasses

Dictionary, MarshaledConnection

Constant Summary collapse

CONNECTION_OPTIONS =
{
:router => FastCache::BasicRouter}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Memcache::Protocol

#add, #cas, #decr, #delete, #flush_all_caches, #flush_cache, #get, #incr, #replace, #reset_connections, #set, #stats

Constructor Details

#initialize(nodes, opts = nil) ⇒ Connection

Returns a new instance of Connection.



9
10
11
12
13
# File 'lib/fastcache/interface/connection.rb', line 9

def initialize(nodes, opts = nil)
  opts = CONNECTION_OPTIONS.merge(opts || {})
  @nodes = nodes.map {|(host, port)| FastCache::Memcache::Node.new(host, port)}
  @router = opts[:router].new(@nodes)
end

Instance Attribute Details

#routerObject

Returns the value of attribute router.



4
5
6
# File 'lib/fastcache/interface/connection.rb', line 4

def router
  @router
end

Instance Method Details

#close_all_connectionsObject



15
16
17
# File 'lib/fastcache/interface/connection.rb', line 15

def close_all_connections
  @nodes.each do |node| node.close end
end