diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-12 23:00:53 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-12 23:00:53 +0100 |
commit | 8e331713f2496396405787e4364bad9e0ac529fa (patch) | |
tree | b21e122edecaa8c57b3d2f26a4ff30a7c0639af0 /actionview/lib/action_view/renderer | |
parent | a88c5ff96de98b67c75a04711847b3a29c2df411 (diff) | |
download | rails-8e331713f2496396405787e4364bad9e0ac529fa.tar.gz rails-8e331713f2496396405787e4364bad9e0ac529fa.tar.bz2 rails-8e331713f2496396405787e4364bad9e0ac529fa.zip |
Write to collection cache where the template is rendered.
Moves us closer to having access to a local template variable,
we can ask for eligibility and its virtual_path.
Currently we rely on `@template`, which we don't have available
when rendering collections without a fixed template.
Diffstat (limited to 'actionview/lib/action_view/renderer')
-rw-r--r-- | actionview/lib/action_view/renderer/partial_renderer.rb | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb | 17 |
2 files changed, 15 insertions, 9 deletions
diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index bdbf03191a..a9bd257e76 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -428,6 +428,8 @@ module ActionView layout = find_template(layout, @template_keys) end + collection_cache_eligible = automatic_cache_eligible? + partial_iteration = PartialIteration.new(@collection.size) locals[iteration] = partial_iteration @@ -436,6 +438,11 @@ module ActionView locals[counter] = partial_iteration.index content = template.render(view, locals) + + if collection_cache_eligible + collection_cache_rendered_partial(content, object) + end + content = layout.render(view, locals) { content } if layout partial_iteration.iterate! content diff --git a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb index c353eb0b31..a037424498 100644 --- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb +++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb @@ -51,16 +51,15 @@ module ActionView end def fetch_or_cache_partial(cached_partials, order_by:) - rely_on_individual_cache_call = !callable_cache_key? - order_by.map do |key| - cached_partials.fetch(key) do - yield.tap do |rendered_partial| - unless rely_on_individual_cache_call - collection_cache.write(key, rendered_partial, @options[:cache_options]) - end - end - end + cached_partials.fetch(key) { yield } + end + end + + def collection_cache_rendered_partial(rendered_partial, key_by) + if callable_cache_key? + key = expanded_cache_key(@options[:cache].call(key_by)) + collection_cache.write(key, rendered_partial, @options[:cache_options]) end end end |