Catalyst::Plugin::DetachIfNotModified - Short-circuit requests with If-Modified-Since headers
version v0.1.0
In your Catalyst class:
use Catalyst qw/ DetachIfNotModified /;
In a controller method:
my $item = ... $c->detach_if_not_modified_since( $item->timestamp ); # Do some CPU-intensive stuff or generate response body here.
This plugin will allow your Catalyst app to handle requests with If-Modified-Since headers.
If-Modified-Since
If the content of a web page has not been modified since a given date, you can quickly bail out and avoid generating a web page that you do not need to.
This can improve the performance of your website.
This should be used with Plack::Middleware::ConditionalGET.
$c->detach_if_not_modified_since( $timestamp );
This sets the Last-Modified header in the response to the $timestamp, and checks if the request contains a If-Modified-Since header that not less than the timestamp. If it does, then it will set the response status code to 304 (Not Modified) and detach.
Last-Modified
$timestamp
304
The $timestamp may be a unix epoch, or an object with an epoch method, such as a DateTime object.
epoch
Be careful when aggregating a collection of objects into a single timestamp, e.g. the maximum timestamp from a list. If a member is removed from that collection, then the maximum timestamp won't be affected, and the result is that an outdated web page may be cached by user agents.
Catalyst
Catalyst::Plugin::Cache::HTTP::Preempt
Plack::Middleware::ConditionalGET
The development version is on github at https://github.com/robrwo/Catalyst-Plugin-DetachIfNotModified and may be cloned from git://github.com/robrwo/Catalyst-Plugin-DetachIfNotModified.git
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/Catalyst-Plugin-DetachIfNotModified/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Robert Rothenberg <rrwo@cpan.org>
This module is based on code created for Science Photo Library https://www.sciencephoto.com.
This software is Copyright (c) 2020 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Catalyst::Plugin::DetachIfNotModified, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::DetachIfNotModified
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::DetachIfNotModified
For more information on module installation, please visit the detailed CPAN module installation guide.