aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@github.com>2019-03-15 14:19:17 -0700
committerGitHub <noreply@github.com>2019-03-15 14:19:17 -0700
commitd7e4cb87d3e3aa2aef7d8688fa1e7984337d1cbb (patch)
tree5672eef481a44b05db62bee20e7ce1ba9219007d /actionview/lib/action_view/template
parent905018fc184d0f00cbc5c54911d473d705acb1eb (diff)
parent80c0ae7de867071ea6abee865364092783ca3d0a (diff)
downloadrails-d7e4cb87d3e3aa2aef7d8688fa1e7984337d1cbb.tar.gz
rails-d7e4cb87d3e3aa2aef7d8688fa1e7984337d1cbb.tar.bz2
rails-d7e4cb87d3e3aa2aef7d8688fa1e7984337d1cbb.zip
Merge pull request #35623 from jhawthorn/actionview_cache
Make Template::Resolver always cache
Diffstat (limited to 'actionview/lib/action_view/template')
-rw-r--r--actionview/lib/action_view/template/resolver.rb40
1 files changed, 3 insertions, 37 deletions
diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb
index 1dc9c9919a..07c44307ff 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
@@ -218,8 +190,7 @@ module ActionView
virtual_path: path.virtual,
format: format,
variant: variant,
- locals: locals,
- updated_at: mtime(template)
+ locals: locals
)
end
end
@@ -272,11 +243,6 @@ module ActionView
entry.gsub(/[*?{}\[\]]/, '\\\\\\&')
end
- # Returns the file mtime from the filesystem.
- def mtime(p)
- File.mtime(p)
- end
-
# Extract handler, formats and variant from path. If a format cannot be found neither
# from the path, or the handler, we should return the array of formats given
# to the resolver.