module ActionController::EtagWithTemplateDigest

When our views change, they should bubble up into HTTP cache freshness and bust browser caches. So the template digest for the current action is automatically included in the ETag.

Enabled by default for apps that use Action View. Disable by setting

config.action_controller.etag_with_template_digest = false

Override the template to digest by passing :template to fresh_when and stale? calls. For example:

# We're going to render widgets/show, not posts/show
fresh_when @post, template: 'widgets/show'

# We're not going to render a template, so omit it from the ETag.
fresh_when @post, template: false

Private Instance Methods

determine_template_etag(options) click to toggle source
# File lib/action_controller/metal/etag_with_template_digest.rb, line 36
def determine_template_etag(options)
  if template = pick_template_for_etag(options)
    lookup_and_digest_template(template)
  end
end
lookup_and_digest_template(template) click to toggle source
# File lib/action_controller/metal/etag_with_template_digest.rb, line 46
def lookup_and_digest_template(template)
  ActionView::Digestor.digest name: template, finder: lookup_context
end
pick_template_for_etag(options) click to toggle source
# File lib/action_controller/metal/etag_with_template_digest.rb, line 42
def pick_template_for_etag(options)
  options.fetch(:template) { "#{controller_name}/#{action_name}" }
end