module ActionController::ConditionalGet

def stale?(object = nil, **freshness_kwargs)


end
super if stale?(@article, template: "widgets/show")
def show

template, you can indicate which digest to include in the ETag:
When rendering a different template than the controller/action's default

The above will set Cache-Control: public, no-cache in the response.

end
end
end
# all the supported formats
respond_to do |format|
@statistics = @articles.really_expensive_call
if stale?(@article, public: true, cache_control: { no_cache: true })

@article = Article.find(params[:id])
def show

options, such as +:public+ and +:cache_control+:
When passing a record or a collection, you can still specify other

recently updated record).
will be set to maximum(:updated_at) (the timestamp of the most
In this case, +etag+ will be set to the collection, and +last_modified+

end
end
end
# all the supported formats
respond_to do |format|
@statistics = @articles.really_expensive_call
if stale?(@articles)

@articles = Article.all
def index

collection of records:
You can also pass an object that responds to +maximum+, such as a

record's +updated_at+.
+etag+ will be set to the record, and +last_modified+ will be set to the

end
end
end
# all the supported formats
respond_to do |format|
@statistics = @article.really_expensive_call
if stale?(@article)

@article = Article.find(params[:id])
def show

You can also just pass a record:

end
end
end
# all the supported formats
respond_to do |format|
@statistics = @article.really_expensive_call
if stale?(etag: @article, last_modified: @article.updated_at)

@article = Article.find(params[:id])
def show

==== Examples

See #fresh_when for supported options.

==== Options

Otherwise, it is fresh, and a 304 Not Modified is sent.
is considered stale, and the response should be rendered from scratch.
against the request. If the request doesn't match the provided options, it
Sets the +etag+ and/or +last_modified+ on the response and checks them
def stale?(object = nil, **freshness_kwargs)
  fresh_when(object, **freshness_kwargs)
  !request.fresh?(response)
end