diff options
author | John Hawthorn <john@hawthorn.email> | 2019-03-14 11:33:28 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2019-03-15 09:20:05 -0700 |
commit | d445ceb9b51ce87a306f331c643808312bd740e5 (patch) | |
tree | 00d4d9d9bb9fa2c81b41446648c2ff03944e9527 /actionview/lib/action_view/template | |
parent | 43fc7b476b483a89dacf9964ccf288f6bc6e1595 (diff) | |
download | rails-d445ceb9b51ce87a306f331c643808312bd740e5.tar.gz rails-d445ceb9b51ce87a306f331c643808312bd740e5.tar.bz2 rails-d445ceb9b51ce87a306f331c643808312bd740e5.zip |
Make Template::Resolver always cache
All actionview caches are already cleared at the start of each request
(when Resolver.caching is false) by PerExecutionDigestCacheExpiry, which
calls LookupContext::DetailsKey.clear (which clears all caches).
Because caches are always cleared per-request in dev, we shouldn't need
this extra logic to compare mtimes and conditionally reload templates.
This should make templates slightly faster in development (particularly
multiple renders of the same template)
Diffstat (limited to 'actionview/lib/action_view/template')
-rw-r--r-- | actionview/lib/action_view/template/resolver.rb | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 1dc9c9919a..eeb7cce61e 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -63,26 +63,11 @@ module ActionView # Cache the templates returned by the block def cache(key, name, prefix, partial, locals) - if Resolver.caching? - @data[key][name][prefix][partial][locals] ||= canonical_no_templates(yield) - else - fresh_templates = yield - cached_templates = @data[key][name][prefix][partial][locals] - - if templates_have_changed?(cached_templates, fresh_templates) - @data[key][name][prefix][partial][locals] = canonical_no_templates(fresh_templates) - else - cached_templates || NO_TEMPLATES - end - end + @data[key][name][prefix][partial][locals] ||= canonical_no_templates(yield) end def cache_query(query) # :nodoc: - if Resolver.caching? - @query_cache[query] ||= canonical_no_templates(yield) - else - yield - end + @query_cache[query] ||= canonical_no_templates(yield) end def clear @@ -112,19 +97,6 @@ module ActionView def canonical_no_templates(templates) templates.empty? ? NO_TEMPLATES : templates end - - def templates_have_changed?(cached_templates, fresh_templates) - # if either the old or new template list is empty, we don't need to (and can't) - # compare modification times, and instead just check whether the lists are different - if cached_templates.blank? || fresh_templates.blank? - return fresh_templates.blank? != cached_templates.blank? - end - - cached_templates_max_updated_at = cached_templates.map(&:updated_at).max - - # if a template has changed, it will be now be newer than all the cached templates - fresh_templates.any? { |t| t.updated_at > cached_templates_max_updated_at } - end end cattr_accessor :caching, default: true |