Class: Cachetastic::Connection
- 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
-
#connections ⇒ Object
Returns the value of attribute connections.
Instance Method Summary collapse
-
#get(name) ⇒ Object
Takes the name of the cache, that’s been methodized, and returns back the adapter object associated with the cache.
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize ⇒ Connection
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
#connections ⇒ Object
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 |