Module: Cell::Caching

Included in:
ViewModel
Defined in:
lib/cell/caching.rb,
lib/cell/caching/notification.rb

Defined Under Namespace

Modules: ClassMethods, Notifications

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# 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 = Uber::Options.new({})
  end
end

Instance Method Details

#cache?(state, *args) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cell/caching.rb', line 59

def cache?(state, *args)
  perform_caching? and state_cached?(state) and self.class.conditional_procs[state].evaluate(self, *args)
end

#cache_storeObject

we want to use DI to set a cache store in cell/rails.



55
56
57
# File 'lib/cell/caching.rb', line 55

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) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/cell/caching.rb', line 45

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].evaluate(self, *args))
  options = self.class.cache_options.eval(state, self, *args)

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