From 7e74a01f849db3b85ac04ce425461c22b2b191d3 Mon Sep 17 00:00:00 2001 From: Josh Lauer Date: Mon, 5 Aug 2013 16:36:47 -0400 Subject: Only cache template digests if config.cache_template_loading since ActionView::Resolver.caching is set to the same value as config.cache_template_loading only cache template digests if config.cache_template_loading is not falsy fixes issues #10752 and #10791 --- actionview/CHANGELOG.md | 6 ++++++ actionview/lib/action_view/digestor.rb | 10 +++++++--- actionview/test/template/digestor_test.rb | 13 +++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 98b78a7114..8fdbe15dee 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,9 @@ +* Only cache template digests if config.cache_template_loading, since + ActionView::Resolver.caching is set to the same value as + config.cache_template_loading + + *Josh Lauer* *Justin Ridgewell* + * Added an `extname` hash option for `javascript_include_tag` method. Before: diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index 64239c81b2..95c3200c81 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -32,9 +32,13 @@ module ActionView Digestor end - @@cache[cache_key] = digest = klass.new(name, format, finder, options).digest # Store the actual digest - ensure - @@cache.delete_pair(cache_key, false) if pre_stored && !digest # something went wrong, make sure not to corrupt the @@cache + # Store the actual digest if config.cache_template_loading is true + klass.new(name, format, finder, options).digest.tap do |digest| + @@cache[cache_key] = digest if ActionView::Resolver.caching? + end + rescue Exception + @@cache.delete_pair(cache_key, false) if pre_stored # something went wrong, make sure not to corrupt the @@cache + raise end end diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 67e3775f28..c6608e214a 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -184,6 +184,15 @@ class TemplateDigestorTest < ActionView::TestCase assert_not_equal digest_phone, digest_fridge_phone end + def test_cache_template_loading + resolver_before = ActionView::Resolver.caching + ActionView::Resolver.caching = false + assert_digest_difference("messages/edit", true) do + change_template("comments/_comment") + end + ActionView::Resolver.caching = resolver_before + end + private def assert_logged(message) old_logger = ActionView::Base.logger @@ -200,9 +209,9 @@ class TemplateDigestorTest < ActionView::TestCase end end - def assert_digest_difference(template_name) + def assert_digest_difference(template_name, persistent = false) previous_digest = digest(template_name) - ActionView::Digestor.cache.clear + ActionView::Digestor.cache.clear unless persistent yield -- cgit v1.2.3