Method: ScrivitoHelper#scrivito_cache

Defined in:
app/helpers/scrivito_helper.rb

#scrivito_cache(key, options = {}, &block) ⇒ Object

This method wraps Rails’ built-in fragment caching to work with content delivered by Scrivito. Fragment caching applies to computed parts of views and helps to improve performance. The Rails guides provide an excellent introduction to caching if you haven’t used it yet.

The scrivito_cache method extends built-in fragment caching so that cached parts of a view are automatically recomputed when Scrivito content changes. The fragments are only cached for the published content. In editable working copies no caching takes place, and the fragments are computed for every request.

Parameters:

  • key (String)

    a name describing the data to be cached.

  • options (Hash) (defaults to: {})

    a hash that enables further configuration of the fragment cache. The options are passed to the cache helper of Rails. See the Rails documentation for details.



455
456
457
458
# File 'app/helpers/scrivito_helper.rb', line 455

def scrivito_cache(key, options={}, &block)
  workspace = Scrivito::Workspace.current
  cache_if(workspace.published? && !scrivito_user, [workspace.cache_key, key], options, &block)
end