Module: Cachetastic::Adapters

Defined in:
lib/cachetastic/adapters/base.rb,
lib/cachetastic/adapters/file.rb,
lib/cachetastic/adapters/dalli.rb,
lib/cachetastic/adapters/redis.rb,
lib/cachetastic/adapters/mongoid.rb,
lib/cachetastic/adapters/memcached.rb,
lib/cachetastic/adapters/local_memory.rb

Defined Under Namespace

Classes: Base, Dalli, File, LocalMemory, Memcached, Mongoid, Redis

Class Method Summary collapse

Class Method Details

.build(klass) ⇒ Object

This method will return the appropriate Cachetastic::Adapters::Base class that is defined for the Class passed in. If an adapter has not been defined for the Class than the default adapter is returned.

Examples:

configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
configatron.cachetastic.user.adapter = Cachetastic::Adapters::Memcached
Cachetastic::Adapters.build(User).class # => Cachetastic::Adapters::Memcached
Cachetastic::Adapters.build(Comment).class # => Cachetastic::Adapters::LocalMemory

16
17
18
19
20
21
22
# File 'lib/cachetastic/adapters/base.rb', line 16

def build(klass)
  adp = klass.to_configatron(:cachetastic).adapter
  if adp.nil?
    adp = configatron.cachetastic.defaults.adapter
  end
  adp.new(klass)
end