This blog is part of our Rails 5 series.
Fragment cache helps in caching parts of the view instead of caching the entire view. Fragment caching is used when different parts of the view need to be cached and expired separately. Before Rails 5, fragment caching was supported only in Action View templates.
Rails 5 provides fragment caching in Action Mailer views . To use this feature, we need to configure our application as follows.
This configuration specifies whether mailer templates should perform fragment caching or not.
By default, this is set to
false for all environments.
Fragment caching in views
We can do caching in mailer views similar to application views using
Following example shows usage of fragment caching in mailer view of the welcome mail.
When we render view for the first time, we can see cache digest of the view and its partial.
We can also use fragment caching in partials of the action mailer views with
Fragment caching is also supported in multipart emails.