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.
logger | [R] | attr_reader :logging |
name | [R] | attr_reader :all_options attr_reader :store_options attr_reader :servers |
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
# 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
# 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
# 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.
# 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
# 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