| Module | Cell::Caching |
| In: |
lib/cell/caching.rb
|
To improve performance rendered state views can be cached using Rails’ caching mechanism. If this it configured (e.g. using our fast friend memcached) all you have to do is to tell Cells which state you want to cache. You can further attach a proc for deciding versions or to instruct re-rendering.
As always I stole a lot of code, this time from Lance Ivy <cainlevy@gmail.com> and his fine components plugin at github.com/cainlevy/components.
Call the versioning Proc for the respective state.
# File lib/cell/caching.rb, line 106
106: def call_version_proc_for_state(state)
107: version_proc = version_proc_for_state(state)
108: return unless version_proc ### DISCUSS: what to do if there's simply nothing?
109:
110: return version_proc.call(self) if version_proc.kind_of? Proc
111: send(version_proc)
112: end
# File lib/cell/caching.rb, line 73
73: def render_state_with_caching(state)
74: return render_state_without_caching(state) unless state_cached?(state)
75:
76: key = cache_key(state, call_version_proc_for_state(state))
77: ### DISCUSS: see sweep discussion at #cache.
78:
79: # cache hit:
80: if content = read_fragment(key)
81: return content
82: end
83: # re-render:
84: return write_fragment(key, render_state_without_caching(state))
85: end
# File lib/cell/caching.rb, line 101
101: def state_cached?(state); version_proc_for_state(state); end