aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorCory Gwin @gwincr11 <gwincr11@github.com>2017-07-26 19:54:41 -0400
committerCory Gwin @gwincr11 <gwincr11@github.com>2017-08-30 08:36:58 -0400
commit49f6c47e418ff1626c6e8c408d11f839d28ceb31 (patch)
treeaeca69275d9c3b871f9ece7c9e6ad860be047b9d /guides
parent9569a0cde832fcd0aaa078ebb1067e6dd3e22d90 (diff)
downloadrails-49f6c47e418ff1626c6e8c408d11f839d28ceb31.tar.gz
rails-49f6c47e418ff1626c6e8c408d11f839d28ceb31.tar.bz2
rails-49f6c47e418ff1626c6e8c408d11f839d28ceb31.zip
Add documentation about template partial caching
Motivation: - #29423 surfaced some confusion about how template caching works when using partials across files with different mime types. This doc attempts to explain how this can be accomplished.
Diffstat (limited to 'guides')
-rw-r--r--guides/source/caching_with_rails.md24
1 files changed, 21 insertions, 3 deletions
diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md
index 6cdce5c2f4..45dcf960e7 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
@@ -387,9 +405,9 @@ store is not appropriate for large application deployments. However, it can
work well for small, low traffic sites with only a couple of server processes,
as well as development and test environments.
-New Rails projects are configured to use this implementation in development environment by default.
+New Rails projects are configured to use this implementation in development environment by default.
-NOTE: Since processes will not share cache data when using `:memory_store`,
+NOTE: Since processes will not share cache data when using `:memory_store`,
it will not be possible to manually read, write or expire the cache via the Rails console.
### ActiveSupport::Cache::FileStore
@@ -580,7 +598,7 @@ Caching in Development
----------------------
It's common to want to test the caching strategy of your application
-in development mode. Rails provides the rake task `dev:cache` to
+in development mode. Rails provides the rake task `dev:cache` to
easily toggle caching on/off.
```bash