Namespace

Files

Cell::Caching

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 to expire the cached view.

As always I stole a lot of code, this time from Lance Ivy and his fine components plugin at github.com/cainlevy/components.

Public Instance Methods

cache_options() click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 149
  def cache_options;        self.class.cache_options;  end
call_version_proc_for_state(state) click to toggle source

Call the versioning Proc for the respective state.

# File lib/cell/caching.rb, line 134
  def call_version_proc_for_state(state)
    version_proc = version_procs[state]
    
    return {} unless version_proc # call to #cache was without any args.
    
    return version_proc.call(self) if version_proc.kind_of? Proc
    send(version_proc)
  end
render_state_with_caching(state) click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 106
  def render_state_with_caching(state)
    return render_state_without_caching(state) unless state_cached?(state) 
    
    key = cache_key(state, call_version_proc_for_state(state))
    ### DISCUSS: see sweep discussion at #cache.
    
    # cache hit:
    if content = read_fragment(key)
      return content 
    end
    # re-render:
    return write_fragment(key, render_state_without_caching(state), cache_options[state])
  end
state_cached?(state) click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 147
  def state_cached?(state); self.class.version_procs.has_key?(state);  end
version_procs() click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 148
  def version_procs;        self.class.version_procs;  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.