Permalink
Browse files

Merge pull request #11768 from cloudspace/cache_template_loading

Only cache template digests if !config.cache_template_loading
  • Loading branch information...
rafaelfranca committed Aug 27, 2013
2 parents 7967fa9 + 7e74a01 commit d6854dfe13ae0b6cd683c69f35635d44954b7cc6
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 d6854df

Please sign in to comment.