cached (key, path_info, details, locals)
private
Handles templates caching. If a key is given and caching is on always check
the cache before hitting the resolver. Otherwise, it always hits the
resolver but check if the resolver is fresher before returning it.
Show source # File actionpack/lib/action_view/template/resolver.rb, line 70
def cached(key, path_info, details, locals) #:nodoc:
name, prefix, partial = path_info
locals = locals.map { |x| x.to_s }.sort!
if key && caching?
@cached[key][name][prefix][partial][locals] ||= decorate(yield, path_info, details, locals)
else
fresh = decorate(yield, path_info, details, locals)
return fresh unless key
scope = @cached[key][name][prefix][partial]
cache = scope[locals]
mtime = cache && cache.map(&:updated_at).max
if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime }
scope[locals] = fresh
else
cache
end
end
end