]> iEval git - plack-app-gruntmaster.git/commitdiff
Merge cache-control changes from master
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 7 Feb 2014 15:57:36 +0000 (17:57 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 7 Feb 2014 15:57:36 +0000 (17:57 +0200)
app.psgi
lib/Gruntmaster/Page/Base.pm
lib/Gruntmaster/Page/Log.pm

index 20092c9bda0da036e7597ce1da2eddbad3530357..5bed878e4767c9806ea4aeba7e533b3278f68ba6 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -55,7 +55,8 @@ sub authenticate {
 
 builder {
        enable 'ContentLength';
-       enable 'Static', path => qr,/static/,;
+       enable_if { $_[0]->{PATH_INFO} =~ qr,^/static/,} Header => set => ['Cache-Control', 'public, max-age=604800'];
+       enable 'Static', path => qr,^/static/,;
        enable 'Log4perl', category => 'plack', conf => 'log.conf';
        enable \&require_admin;
        enable_if \&some_auth_required, 'Auth::Basic', authenticator => \&authenticate, realm => 'Gruntmaster 6000';
index 8883cade99857c545ceef429a698266598a21bc4..ee8a3101768148125a468ce5bb71f55d5348ad4c 100644 (file)
@@ -31,7 +31,7 @@ sub import {
                local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
                $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]})
        };
-       *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] };
+       *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] };
        *{"${caller}::purge"} = sub {
                return unless $ENV{PURGE_HOST};
                my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]");
@@ -176,11 +176,13 @@ sub generate{
        $self->_generate($htc, $lang, @args);
        my $out = $htc->output;
        utf8::downgrade($out);
-       [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ $out ] ]
+       [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ]
 }
 
 sub _generate {}
 
+sub max_age { 60 }
+
 sub variants {
        [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ]
 }
index 4773fecaaac7b86326855b350f60bebce4b7d64e..9192d9580b2b198d6eb30783917c124eaeabf216 100644 (file)
@@ -55,4 +55,6 @@ sub _generate{
        $htc->param(prev => $page - 1) unless $page == 1;
 }
 
+sub max_age { 5 }
+
 1
This page took 0.037674 seconds and 4 git commands to generate.