Class: Cachetastic::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gems/cachetastic-2.1.2/lib/cachetastic/connection.rb

Overview

This class caches adapter objects for each cache in the system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



7
8
9
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/connection.rb', line 7

def initialize
  self.connections = {}
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



5
6
7
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/connection.rb', line 5

def connections
  @connections
end

Instance Method Details

#get(name) ⇒ Object

Takes the name of the cache, that’s been methodized, and returns back the adapter object associated with the cache. If the adapter object doesn’t exist or if the adapter is no longer valid (adapter.valid?) a new one is created and returned.



14
15
16
17
18
19
20
21
22
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/connection.rb', line 14

def get(name)
  name = name.to_sym
  conn = self.connections[name]
  return conn if conn && conn.valid?
  adapter = Cachetastic::Adapters::Base.configuration(name).adapter.to_s.camelcase
  conn = "Cachetastic::Adapters::#{adapter}".constantize.new(name)
  self.connections[name.to_sym] = conn
  return conn
end