aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/cache_helper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-24 11:29:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-24 11:29:16 -0800
commita5776ed2b2bf8bccb083e303992a174110b3ef7f (patch)
treecfef331bdccd3742e2696a5e2f50312d2f4e132d /actionview/lib/action_view/helpers/cache_helper.rb
parent0c9f5f56f7a1628c8c9ff3a91a52f17a15e31b26 (diff)
parentf6fecabc0cb8ad7be3783d31656a0b10fe3b5bc7 (diff)
downloadrails-a5776ed2b2bf8bccb083e303992a174110b3ef7f.tar.gz
rails-a5776ed2b2bf8bccb083e303992a174110b3ef7f.tar.bz2
rails-a5776ed2b2bf8bccb083e303992a174110b3ef7f.zip
Merge branch 'master' into treewip
* master: (113 commits) remove useless method Updated file documentation [ci skip] changes caching guide to add note on weak etags Don't put config.action_mailer.perform_caching entry twice in development.rb Fix wording and wrong reference Add Ruby formatting to CHANGELOG entry Fix ActionView's cache section reference Do not define methods in the included block Add caching guide in ActionMailer basics Add ActionMailer configuration options Preparing for 5.0.0.beta3 release Update 5.0 release notes Enable tmp_restart plugin for puma Prep release for Rails 5 beta3 [ci skip] Move collection caching changelog entry. Ensure `drop_table` even if tests failure or interrupted :bomb: run the test @rafaelfranca :angry: Remove changelog entry for reverted commit Add CHANGELOG for https://github.com/rails/rails/pull/23734 [ci skip] No need CHANGELOG entry for #23849. ...
Diffstat (limited to 'actionview/lib/action_view/helpers/cache_helper.rb')
-rw-r--r--actionview/lib/action_view/helpers/cache_helper.rb45
1 files changed, 15 insertions, 30 deletions
diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb
index 401f398721..4c7c4b91c6 100644
--- a/actionview/lib/action_view/helpers/cache_helper.rb
+++ b/actionview/lib/action_view/helpers/cache_helper.rb
@@ -126,44 +126,29 @@ module ActionView
#
# Now all you have to do is change that timestamp when the helper method changes.
#
- # === Automatic Collection Caching
+ # === Collection Caching
#
- # When rendering collections such as:
+ # When rendering a collection of objects that each use the same partial, a `cached`
+ # option can be passed.
+ # For collections rendered such:
#
- # <%= render @notifications %>
- # <%= render partial: 'notifications/notification', collection: @notifications %>
+ # <%= render partial: 'notifications/notification', collection: @notifications, cached: true %>
#
- # If the notifications/_notification partial starts with a cache call as:
+ # The `cached: true` will make Action View's rendering read several templates
+ # from cache at once instead of one call per template.
#
- # <% cache notification do %>
- # <%= notification.name %>
- # <% end %>
- #
- # The collection can then automatically use any cached renders for that
- # template by reading them at once instead of one by one.
- #
- # See ActionView::Template::Handlers::ERB.resource_cache_call_pattern for
- # more information on what cache calls make a template eligible for this
- # collection caching.
- #
- # The automatic cache multi read can be turned off like so:
+ # Templates in the collection not already cached are written to cache.
#
- # <%= render @notifications, cache: false %>
+ # Works great alongside individual template fragment caching.
+ # For instance if the template the collection renders is cached like:
#
- # === Explicit Collection Caching
- #
- # If the partial template doesn't start with a clean cache call as
- # mentioned above, you can still benefit from collection caching by
- # adding a special comment format anywhere in the template, like:
- #
- # <%# Template Collection: notification %>
- # <% my_helper_that_calls_cache(some_arg, notification) do %>
- # <%= notification.name %>
+ # # notifications/_notification.html.erb
+ # <% cache notification do %>
+ # <%# ... %>
# <% end %>
#
- # The pattern used to match these is <tt>/# Template Collection: (\S+)/</tt>,
- # so it's important that you type it out just so.
- # You can only declare one collection in a partial template file.
+ # Any collection renders will find those cached templates when attempting
+ # to read multiple templates at once.
def cache(name = {}, options = {}, &block)
if controller.respond_to?(:perform_caching) && controller.perform_caching
name_options = options.slice(:skip_digest, :virtual_path)