| Module | Cell::Caching::ClassMethods |
| In: |
lib/cell/caching.rb
|
Activate caching for the state state. If version_proc is omitted, the view will be cached forever. Otherwise you may either directly pass a Proc or provide a Symbol, which is treated as an instance method of the cell. This method is called every time the state is rendered, and is expected to return a Hash containing the cache key ingredients.
Example:
class CachingCell < Cell::Base
cache :versioned_cached_state, Proc.new{ {:version => 0} }
would result in the complete cache key
cells/CachingCell/versioned_cached_state/version=0
If you provide a symbol, you can access the cell instance directly in the versioning method:
class CachingCell < Cell::Base
cache :cached_state, :my_cache_version
def my_cache_version
{ :user => current_user.id,
:item_id => params[:item] }
}
end
results in a very specific cache key, for customized caching:
cells/CachingCell/cached_state/user=18/item_id=1
# File lib/cell/caching.rb, line 60
60: def cache(state, version_proc = Proc.new{Hash.new})
61: #return unless ActionController::Base.cache_configured?
62: version_procs[state] = version_proc
63: end