Module: Cell::Caching

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

Defined Under Namespace

Modules: ClassMethods

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     = {}
  end
end

Instance Method Details

#cache?(state, *args) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# 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_storeObject

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



54
55
56
# 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) ⇒ Object



44
45
46
47
48
49
50
51
52
# 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