Sledge::Plugin::IfModifiedSince - Sledge plugin to control cache by If-Modified-Since header
package Your:Pages; use Sledge::Plugin::IfModifiedSince; sub dispatch_foo { my $self = shift; if ( $self->if_modified_since( time || '/path/to/file' ) ) { # set Last-Modified header by epoch time $self->set_last_modified( time ); # or by path to file $self->set_last_modified( '/path/to/file' ); # output content... } else { $self->not_modified; return; } }
Sledge::Plugin::IfModifiedSince is Sledge plugin to control cache by If-Modified-Since header. use this module in your Pages class, then if_modified_since, not_modified and set_last_modified methods are imported in it.
# check by epoch time my $is_modified = $page->if_modified_since($epoch); # or by mtime my $is_modified = $page->if_modified_since('/path/to/file'); Compare If-Modified-Since header to passed time. You can pass epoch time or path to file as argument.
$page->not_modified; Return 304 Not Modified.
# pass epoch time $self->set_last_modified( time ); # or pass path to file $self->set_last_modified( '/path/to/file' ); Set last modified time in Last-Modified header. You can pass epoch time or path to file as argument.
Yasuhiro Horiuchi <yasuhiro@hori-uchi.com>
To install Sledge::Plugin::IfModifiedSince, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sledge::Plugin::IfModifiedSince
CPAN shell
perl -MCPAN -e shell install Sledge::Plugin::IfModifiedSince
For more information on module installation, please visit the detailed CPAN module installation guide.