module Cell::Caching

Public Class Methods

included(includer) click to toggle source
# File lib/cell/caching.rb, line 5
def self.included(includer)
  includer.class_eval do
    extend ClassMethods
    extend Uber::InheritableAttr
    inheritable_attr :version_procs
    inheritable_attr :conditional_procs
    inheritable_attr :cache_options

    self.version_procs     = {}
    self.conditional_procs = {}
    self.cache_options     = {}
  end
end

Public Instance Methods

cache?(state, *args) click to toggle source
# File lib/cell/caching.rb, line 58
def cache?(state, *args)
  perform_caching? and state_cached?(state) and self.class.conditional_procs[state].(self, *args)
end
cache_store() click to toggle source
# File lib/cell/caching.rb, line 54
def cache_store  # we want to use DI to set a cache store in cell/rails.
  raise "No cache store has been set."
end
render_state(state, *args) click to toggle source
Calls superclass method
# File lib/cell/caching.rb, line 44
def render_state(state, *args)
  state = state.to_sym
  return super(state, *args) unless cache?(state, *args)

  key     = self.class.state_cache_key(state, self.class.version_procs[state].(self, *args))
  options = self.class.cache_options[state].(self, *args)

  fetch_from_cache_for(key, options) { super(state, *args) }
end

Private Instance Methods

fetch_from_cache_for(key, options, &block) click to toggle source
# File lib/cell/caching.rb, line 68
def fetch_from_cache_for(key, options, &block)
  cache_store.fetch(key, options, &block)
end
perform_caching?() click to toggle source
# File lib/cell/caching.rb, line 64
def perform_caching?
  true
end
state_cached?(state) click to toggle source
# File lib/cell/caching.rb, line 72
def state_cached?(state)
  self.class.version_procs.has_key?(state)
end