instance method
cache_root!
Ruby on Rails 2.9.1
Since v2.6.4 Last seen in v2.14.1Signature
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
-
keyopt = nil -
optionsopt = {}
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