Class Cachetastic::Adapters::Base
In: lib/cachetastic/adapters/base.rb
Parent: Object

This class is the interface used to develop adapters for stores. Stores are where the data is actually held. These could be local memory, memcached, a database, the file system, etc… If you implement this API, then you should be able to plug in different stores for your caches without having to change any of your code.

Methods that need to be implemented:

  • setup - used to setup the implementation of the adapter.
  • set(key, object, expiry) - sets an object into the store using the given key and the expiry time.
  • get(key) - returns an object from the store for a given key.
  • delete(key, delay) - deletes an object from the store for a given key. If the store supports it, a delay can be used.
  • expire_all - expires all objects in the store for a given cache.
  • stats - returns statistics for the store.
  • valid? - used to test whether or not the store is still valid. If this returns false a new instance of the adapter is created by Cachetastic::Connection

Methods

Attributes

logger  [R]  attr_reader :logging
name  [R]  attr_reader :all_options attr_reader :store_options attr_reader :servers

Public Class methods

Returns either the options Options need to be specified in configatrion as the methodized name of the cache with _options attached at the end. Examples:

  Cachetastic::Caches::PageCache # => cachetastic_caches_page_cache_options
  MyAwesomeCache # => my_awesome_cache_options

[Source]

    # File lib/cachetastic/adapters/base.rb, line 71
71:     def configuration(name)
72:       name = "#{name}_options"
73:       conf = configatron.retrieve(name, configatron.cachetastic_default_options)
74:       conf
75:     end

[Source]

    # File lib/cachetastic/adapters/base.rb, line 24
24:   def initialize(name)
25:     @name = name
26:     @logger = Cachetastic::Logger.new(configuration.retrieve(:logger, ::Logger.new(STDOUT)))
27:     setup
28:     if self.debug?
29:       self.logger.debug(self.name, :self, self.inspect)
30:     end
31:   end

Public Instance methods

[Source]

    # File lib/cachetastic/adapters/base.rb, line 60
60:   def configuration
61:     Cachetastic::Adapters::Base.configuration(self.name)
62:   end

Returns true/or falsed based on whether or not the debug setting is set to true in the configuration file. If the config setting is set, then false is returned.

[Source]

    # File lib/cachetastic/adapters/base.rb, line 43
43:   def debug?
44:     ivar_cache(:debug) do
45:       configuration.retrieve(:debug, false)
46:     end
47:   end

[Source]

    # File lib/cachetastic/adapters/base.rb, line 49
49:   def stats
50:     cache_name = self.name.to_s.camelize
51:     adapter_type = self.class.to_s.gsub('Cachetastic::Adapters::', '')
52:     s = "Cache: #{cache_name}\nStore Type: #{adapter_type}\n"
53:     if self.servers
54:       servers = self.servers.join(',')
55:       s += "Servers: #{servers}"
56:     end
57:     puts s
58:   end

[Validate]