Actions offer a DSL to set a special header . The first argument is a cache response directive like :public
or "must-revalidate"
, while the second argument is a set of options like :max_age
.
Another HTTP caching special header is Expires
. It can be used for retrocompatibility with old browsers which don’t understand .
Conditional GET is a two step workflow to inform browsers that a resource hasn’t changed since the last visit. At the end of the first request, the response includes special HTTP response headers that the browser will use next time it comes back. If the header matches the value that the server calculates, then the resource is still cached and a 304
status (Not Modified) is returned.
The first way to match a resource freshness is to use an identifier (usually an MD5 token). Let’s specify it with fresh etag:
.
Last Modified
The second way is to use a timestamp via fresh last_modified:
.
If the given timestamp does NOT match If-Modified-Since
request header, it will return a 200
and set the response header with the timestamp value. If the timestamp does match, the action will be halted and a 304
will be returned.