Browse files

Merge pull request #11768 from cloudspace/cache_template_loading

Only cache template digests if !config.cache_template_loading
Conflicts:
	actionview/CHANGELOG.md
  • Loading branch information...
1 parent 8f72b59 commit b351c6f505c74fd9aab7a7a639012d4c89bbf016 @rafaelfranca rafaelfranca committed Aug 27, 2013
Showing with 22 additions and 5 deletions.
  1. +4 −0 actionpack/CHANGELOG.md
  2. +7 −3 actionpack/lib/action_view/digestor.rb
  3. +11 −2 actionpack/test/template/digestor_test.rb
View
4 actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## unreleased ##
+* Only cache template digests if `config.cache_template_loading` is true.
+
+ *Josh Lauer*, *Justin Ridgewell*
+
* Fix an issue where `:if` and `:unless` controller action procs were being run
before checking for the correct action in the `:only` and `:unless` options.
View
10 actionpack/lib/action_view/digestor.rb
@@ -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
View
13 actionpack/test/template/digestor_test.rb
@@ -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 b351c6f

Please sign in to comment.