Class Cachetastic::Caches::Base
In: lib/caches/cachetastic_caches_base.rb
Parent: Object

When creating a new ‘Cache’ this class should be extended. Once extended you‘ll only need to override just the methods that are different for your cache.

  class MyAwesomeCache < Cachetastic::Caches::Base
  end
  MyAwesomeCache.set(1, "One")
  MyAwesomeCache.get(1) # => "One"
  MyAwesomeCache.update(1, "One!!")
  MyAwesomeCache.get(1) # => "One!!"
  MyAwesomeCache.delete(1)
  MyAwesomeCache.get(1) # => nil

  class MyAwesomeCache < Cachetastic::Caches::Base
    class << self
      def get(key)
        super(key) do
          set(key, key * 10)
        end
      end
    end
  end
  MyAwesomeCache.set(1, "One")
  MyAwesomeCache.get(1) # => "One"
  MyAwesomeCache.delete(1)
  MyAwesomeCache.get(1) # => 10

Methods

Classes and Modules

Class Cachetastic::Caches::Base::RegisteredCaches

External Aliases

set -> put

Public Class methods

Returns the underlying Cachetastic::Adapters::Base for this cache.

Returns a list of all registered caches in the system.

Returns a ‘methodize’ version of the cache‘s class name. This gets used in logging, namespacing, and as the key in the Cachetastic::Connection class.

  MyAwesomeCache.cache # => "my_awesome_cache"
  Cachetastic::Caches::Base # => "cachetastic_caches_base"

Deletes an object from the cache. The optional delay parameter sets an offset, in seconds, for when the object should get deleted. The default of 0 means the object gets deleted right away.

Expires all objects for this cache.

Returns an object from the cache for a given key. If the object comes back as nil and a block is given that block will be run and the results of the block will be run. This can be used to JIT caches, just make sure in the block to call the set method because the results of the block are not automatically cached.

Raises a MethodNotImplemented exception. This method should be overridden in the child class to enable a populating the cache with all things that should be in there.

Set a particular object info the cache for the given key. An optional third parameter sets the expiry time for the object in the cache. The default for this expiry is set as either 0, meaning it never expires, or if there‘s a default_expiry time set in the config file, that file will be used. If there is an expiry_swing set in the config file it will be +/- to the expiry time. See also: calculate_expiry_time

A convenience method that returns statistics for the underlying Cachetastic::Adapters::Base for the cache.

Private Class methods

If the expiry time is set to 60 minutes and the expiry_swing time is set to 15 minutes, this method will return a number between 45 minutes and 75 minutes.

[Validate]