diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2015-07-28 23:11:53 +0200 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2015-08-03 12:08:33 +0200 |
commit | f6e48148be5325462ab1cdd9280bd36f26ce3111 (patch) | |
tree | 5f25c71e180d5ff7e46f1e8d778b7e3fc3c90ecd /guides/source | |
parent | da4a37f63cbf792e598a8feaf20b625333dfe3d8 (diff) | |
download | rails-f6e48148be5325462ab1cdd9280bd36f26ce3111.tar.gz rails-f6e48148be5325462ab1cdd9280bd36f26ce3111.tar.bz2 rails-f6e48148be5325462ab1cdd9280bd36f26ce3111.zip |
Add a section about "Collection caching" [ci skip]
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/caching_with_rails.md | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index 3836645b3f..9d03b522bb 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -103,6 +103,29 @@ If you want to cache a fragment under certain conditions, you can use <% end %> ``` +#### Collection caching + +The `render` helper can also cache individual templates rendered for a collection. +It can even one up the previous example with `each` by reading all cache +templates at once instead of one by one. This is done automatically if the template +rendered by the collection includes a `cache` call. Take a collection that renders +a `products/_product.html.erb` partial for each element: + +```ruby +render products +``` + +If `products/_product.html.erb` starts with a `cache` call like so: + +```html+erb +<% cache product do %> + <%= product.name %> +<% end %> + +All the cached templates from previous renders will be fetched at once with much +greater speed. There's more info on how to make your templates [eligible for +collection caching](http://api.rubyonrails.org/classes/ActionView/Template/Handlers/ERB.html#method-i-resource_cache_call_pattern). + ### Russian Doll Caching You may want to nest cached fragments inside other cached fragments. This is |