aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2017-08-30 08:38:53 -0400
committerGitHub <noreply@github.com>2017-08-30 08:38:53 -0400
commit86389b41436e7020a403c72669cf7748850fb15e (patch)
tree9a39a14cb0d25807a0d2e399ff2934c174fd7ae7 /guides
parent87eb1a26da0b1385af07a8347dcfd32998a614ee (diff)
parent49f6c47e418ff1626c6e8c408d11f839d28ceb31 (diff)
downloadrails-86389b41436e7020a403c72669cf7748850fb15e.tar.gz
rails-86389b41436e7020a403c72669cf7748850fb15e.tar.bz2
rails-86389b41436e7020a403c72669cf7748850fb15e.zip
Merge pull request #29964 from gwincr11/cg-partial-caching
Add documentation about template partial caching
Diffstat (limited to 'guides')
-rw-r--r--guides/source/caching_with_rails.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md
index e2ddee3ed5..910a531068 100644
--- a/guides/source/caching_with_rails.md
+++ b/guides/source/caching_with_rails.md
@@ -179,6 +179,24 @@ With `touch` set to `true`, any action which changes `updated_at` for a game
record will also change it for the associated product, thereby expiring the
cache.
+### Shared Partial Caching
+
+It is possible to share partials and associated caching between files with different mime types. For example shared partial caching allows template writers to share a partial between HTML and Javascript files. When templates are collected in the template resolver file paths they only include the template language extension and not the mime type. Because of this templates can be used for multiple mime types. Both HTML and JavaScript requests will respond to the following code:
+
+```ruby
+render(partial: 'hotels/hotel', collection: @hotels, cached: true)
+```
+
+Will load a file named `hotels/hotel.erb`.
+
+Another option is to include the full filename of the partial to render.
+
+```ruby
+render(partial: 'hotels/hotel.html.erb', collection: @hotels, cached: true)
+```
+
+Will load a file named `hotels/hotel.html.erb` in any file mime type, for example you could include this partial in a Javascript file.
+
### Managing dependencies
In order to correctly invalidate the cache, you need to properly define the