diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-25 11:54:07 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-25 11:54:07 -0300 |
commit | 68a2a6711643db6b8b0775fe004bc0de0cdc07db (patch) | |
tree | d18132851add017e8766c533d31cac2c7e939d19 /actionview/lib/action_view/helpers/cache_helper.rb | |
parent | 5a6868b6175167d91fcfaed82b4d4627281a4878 (diff) | |
parent | ca6aba7f30ad9910f17e4c5b39667889d9518794 (diff) | |
download | rails-68a2a6711643db6b8b0775fe004bc0de0cdc07db.tar.gz rails-68a2a6711643db6b8b0775fe004bc0de0cdc07db.tar.bz2 rails-68a2a6711643db6b8b0775fe004bc0de0cdc07db.zip |
Merge pull request #18948 from kaspth/automatic-collection-caching
Merge multi_fetch_fragments.
Diffstat (limited to 'actionview/lib/action_view/helpers/cache_helper.rb')
-rw-r--r-- | actionview/lib/action_view/helpers/cache_helper.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index 9dadfb5ce1..0e2a5f90f4 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -110,6 +110,29 @@ module ActionView # <%= some_helper_method(person) %> # # Now all you'll have to do is change that timestamp when the helper method changes. + # + # === Automatic Collection Caching + # + # When rendering collections such as: + # + # <%= render @notifications %> + # <%= render partial: 'notifications/notification', collection: @notifications %> + # + # If the notifications/_notification partial starts with a cache call like so: + # + # <% 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: + # + # <%= render @notifications, cache: false %> def cache(name = {}, options = nil, &block) if controller.perform_caching safe_concat(fragment_for(cache_fragment_name(name, options), options, &block)) @@ -161,6 +184,14 @@ module ActionView end end + # Given a key (as described in ActionController::Caching::Fragments.expire_fragment), + # returns a key suitable for use in reading, writing, or expiring a + # cached fragment. All keys are prefixed with <tt>views/</tt> and uses + # ActiveSupport::Cache.expand_cache_key for the expansion. + def fragment_cache_key(key) + ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views) + end + private def fragment_name_with_digest(name) #:nodoc: |