Permalink
Browse files

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
  • Loading branch information...
1 parent 9b6a434 commit 7e74a01f849db3b85ac04ce425461c22b2b191d3 Josh Lauer committed Aug 5, 2013
Showing with 24 additions and 5 deletions.
  1. +6 −0 actionview/CHANGELOG.md
  2. +7 −3 actionview/lib/action_view/digestor.rb
  3. +11 −2 actionview/test/template/digestor_test.rb
View
@@ -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:
@@ -32,9 +32,13 @@ def compute_and_store_digest(cache_key, name, format, finder, options) # called
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
@@ -184,6 +184,15 @@ def test_dependencies_via_options_results_in_different_digest
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 @@ def assert_logged(message)
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

0 comments on commit 7e74a01

Please sign in to comment.