instance method
cache!
Ruby on Rails 2.6.4
Since v2.4.1 Last seen in v2.14.1Signature
cache!(key=nil, options={})
Caches the json constructed within the block passed. Has the same signature as the cache helper method in ActionView::Helpers::CacheHelper and so can be used in the same way.
Example:
json.cache! ['v1', @person], expires_in: 10.minutes do json.extract! @person, :name, :age end
Parameters
-
keyopt = nil -
optionsopt = {}
Source
# File lib/jbuilder/jbuilder_template.rb, line 34
def cache!(key=nil, options={})
if @context.controller.perform_caching
value = _cache_fragment_for(key, options) do
_scope { yield self }
end
merge! value
else
yield
end
end
Defined in lib/jbuilder/jbuilder_template.rb line 34
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in JbuilderTemplate