Module: ActionController::EtagWithTemplateDigest
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::ActiveSupport::Concern
|
|
Instance Chain:
self,
ConditionalGet ,
Head
|
|
Defined in: | actionpack/lib/action_controller/metal/etag_with_template_digest.rb |
Overview
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
ConditionalGet
- Attributes & Methods
- .etaggers rw
- #etaggers rw
- .etaggers? ⇒ Boolean rw
- #etaggers? ⇒ Boolean rw
Class Method Summary
::ActiveSupport::Concern
- Extended
class_methods | Define class methods from given block. |
included | Evaluate given block in context of base class, so that you can write class macros here. |
prepended | Evaluate given block in context of base class, so that you can write class macros here. |
append_features, prepend_features |
Instance Method Summary
- #determine_template_etag(options) private
- #lookup_and_digest_template(template) private
-
#pick_template_for_etag(options)
private
Pick the template digest to include in the ETag.
ConditionalGet
- Included
#expires_in | Sets the |
#expires_now | Sets an HTTP 1.1 |
#fresh_when | Sets the |
#http_cache_forever | Cache or yield the block. |
#no_store | Sets an HTTP 1.1 |
#stale? | Sets the |
#combine_etags |
Head
- Included
#head | Returns a response that has no content (merely headers). |
#include_content? |
DSL Calls
included
[ GitHub ]30 31 32 33 34 35 36
# File 'actionpack/lib/action_controller/metal/etag_with_template_digest.rb', line 30
included do class_attribute :etag_with_template_digest, default: true etag do || determine_template_etag( ) if etag_with_template_digest end end
Class Attribute Details
.etaggers (rw)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/conditional_get.rb', line 15
class_attribute :etaggers, default: []
.etaggers? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionpack/lib/action_controller/metal/conditional_get.rb', line 15
class_attribute :etaggers, default: []
Instance Attribute Details
#etaggers (rw)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/conditional_get.rb', line 15
class_attribute :etaggers, default: []
#etaggers? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionpack/lib/action_controller/metal/conditional_get.rb', line 15
class_attribute :etaggers, default: []
Instance Method Details
#determine_template_etag(options) (private)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/etag_with_template_digest.rb', line 39
def determine_template_etag( ) if template = pick_template_for_etag( ) lookup_and_digest_template(template) end end
#lookup_and_digest_template(template) (private)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/etag_with_template_digest.rb', line 55
def lookup_and_digest_template(template) ActionView::Digestor.digest name: template, format: nil, finder: lookup_context end
#pick_template_for_etag(options) (private)
Pick the template digest to include in the ETag. If the :template
option is present, use the named template. If :template
is nil
or absent, use the default controller/action template. If :template
is false, omit the template digest from the ETag.
# File 'actionpack/lib/action_controller/metal/etag_with_template_digest.rb', line 49
def pick_template_for_etag( ) unless [:template] == false [:template] || lookup_context.find_all(action_name, _prefixes).first&.virtual_path end end