Files

Cell::Caching::ClassMethods

Public Instance Methods

cache(state, version_proc=nil, cache_opts={}) click to toggle source

Activate caching for the state state. If no other options are passed the view will be cached forever.

You may pass a Proc or a Symbol as cache expiration version_proc. This method is called every time the state is rendered, and is expected to return a Hash containing the cache key ingredients.

Additional options will be passed directly to the cache store when caching the state. Useful for simply setting a TTL for a cached state. Note that you may omit the version_proc.

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

You may also set a TTL only, e.g. when using the memcached store:

 cache :cached_state, :expires_in => 3.minutes

Or use both, having a versioning proc and a TTL expiring the state as a fallback after a certain amount of time.

 cache :cached_state, Proc.new { {:version => 0} }, :expires_in => 10.minutes
# File lib/cell/caching.rb, line 73
    def cache(state, version_proc=nil, cache_opts={})
      if version_proc.is_a?(Hash)
        cache_opts    = version_proc
        version_proc  = nil
      end
      
      version_procs[state]  = version_proc
      cache_options[state]  = cache_opts
    end
cache_options() click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 84
    def cache_options;  @cache_options    ||= {}; end
expire_cache_key(key, opts=nil) click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 99
    def expire_cache_key(key, opts=nil)
      cache_store.delete(key, opts)
    end
version_procs() click to toggle source

(Not documented)

# File lib/cell/caching.rb, line 83
    def version_procs;  @version_procs    ||= {}; end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.