instance method cache_root!

Ruby on Rails 2.10.2

Since v2.6.4 Last seen in v2.14.1

Available in: v2.6.4 v2.7.0 v2.8.0 v2.9.1 v2.10.2 v2.11.5 v2.12.0 v2.13.0 v2.14.1

Signature

cache_root!(key=nil, options={})

Caches the json structure at the root using a string rather than the hash structure. This is considerably faster, but the drawback is that it only works, as the name hints, at the root. So you cannot use this approach to cache deeper inside the hierarchy, like in partials or such. Continue to use #cache! there.

Example:

json.cache_root! @person do
  json.extract! @person, :name, :age
end

# json.extra 'This will not work either, the root must be exclusive'

Parameters

key opt = nil
options opt = {}
Source
# File lib/jbuilder/jbuilder_template.rb, line 57
  def cache_root!(key=nil, options={})
    if @context.controller.perform_caching
      raise "cache_root! can't be used after JSON structures have been defined" if @attributes.present?

      @cached_root = _cache_fragment_for([ :root, key ], options) { yield; target! }
    else
      yield
    end
  end

Defined in lib/jbuilder/jbuilder_template.rb line 57 · View on GitHub · Improve this page · Find usages on GitHub

Defined in JbuilderTemplate

Type at least 2 characters to search.

↑↓ navigate · open · esc close