Class: Cachetastic::Adapters::Base
- Defined in:
- lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb
Overview
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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
attr_reader :logging.
-
#name ⇒ Object
readonly
attr_reader :all_options attr_reader :store_options attr_reader :servers.
Class Method Summary collapse
-
.configuration(name) ⇒ Object
Returns either the options Options need to be specified in configatrion as the methodized name of the cache with _options attached at the end.
Instance Method Summary collapse
- #configuration ⇒ Object
-
#debug? ⇒ Boolean
Returns true/or falsed based on whether or not the debug setting is set to true in the configuration file.
-
#initialize(name) ⇒ Base
constructor
A new instance of Base.
- #stats ⇒ Object
Constructor Details
#initialize(name) ⇒ Base
Returns a new instance of Base.
24 25 26 27 28 29 30 31 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 24 def initialize(name) @name = name @logger = Cachetastic::Logger.new(configuration.retrieve(:logger, ::Logger.new(STDOUT))) setup if self.debug? self.logger.debug(self.name, :self, self.inspect) end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
attr_reader :logging
22 23 24 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 22 def logger @logger end |
#name ⇒ Object (readonly)
attr_reader :all_options attr_reader :store_options attr_reader :servers
20 21 22 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 20 def name @name end |
Class Method Details
.configuration(name) ⇒ Object
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
69 70 71 72 73 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 69 def configuration(name) name = "#{name}_options" conf = configatron.retrieve(name, configatron.) conf end |
Instance Method Details
#configuration ⇒ Object
58 59 60 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 58 def configuration Cachetastic::Adapters::Base.configuration(self.name) end |
#debug? ⇒ Boolean
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.
43 44 45 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 43 def debug? configuration.retrieve(:debug, false) end |
#stats ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/base.rb', line 47 def stats cache_name = self.name.to_s.camelize adapter_type = self.class.to_s.gsub('Cachetastic::Adapters::', '') s = "Cache: #{cache_name}\nStore Type: #{adapter_type}\n" if self.servers servers = self.servers.join(',') s += "Servers: #{servers}" end puts s end |