A Plugin to set the HTTP-Expires header of the response or any of the Cache-Directives, like max-age
Setting the HTTP response headers 'Expire' and 'Cache-Control' according to RFC 7234
use Dancer2;
use Dancer2::Plugin::HTTP::Caching;
get '/aging' => sub {
http_cache_max_age 3600; # one hour
http_cache_private;
http_cache_must_revalidate;
http_cache_no_cache 'Set-Cookie';
http_cache_no_cache 'WWW-Authenticate';
http_expire 'Thu, 31 Dec 2015 23:23:59 GMT';
"This content must be refreshed within 1 Hour\"
};
That RFC describes a lot on how to store and respond with cached data. But basically, to make caching work it falls in two parts:
-
A origin server that SHOULD provide a expiration-date and or directives that tell the cache long it can hold the data. That is basically enough for web-server to do, sending off information about freshness.
-
A caching server that once in a while checks with the origin server what to do with it's cached-data, a process called validation. Validation is handled by conditional-requests using request headers like 'If-Modified-Since' and when not, the server SHOULD send a status of 304 (Not Modified).
Handling conditional requests by the server is beyond the scope of this caching plugin, and is not described as such in the RFC. For this to work, use the Dancer2::Plugin::HTTP-ConditionalRequest
Only the first from the list below has it's own HTTP =response header field, all others, when used, will be appended to the HTTP Cache-Control response header field. Some of those take parameters.
See the RFC for a explanation of what these keywords would mean
Theo van Hoesel, C<< <Th.J.v.Hoesel at THEMA-MEDIA.nl> >>