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
such as `:public` and `:cache_control`:
When passing a record or a collection, you can still specify other options,
record).
be set to `maximum(:updated_at)` (the timestamp of the most recently updated
In this case, `etag` will be set to the collection, and `last_modified` will
end
end
end
# all the supported formats
respond_to do |format|
@statistics = @articles.really_expensive_call
if stale?(@articles)
@articles = Article.all
def index
of records:
You can also pass an object that responds to `maximum`, such as a collection
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
it is fresh, and a `304 Not Modified` is sent.
considered stale, and the response should be rendered from scratch. Otherwise,
the request. If the request doesn't match the provided options, it is
Sets the `etag` and/or `last_modified` on the response and checks them against
def stale?(object = nil, **freshness_kwargs) fresh_when(object, **freshness_kwargs) !request.fresh?(response) end