]> iEval git - plack-app-gruntmaster.git/commitdiff
Add Cache-Control to most requests
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 7 Feb 2014 15:42:35 +0000 (17:42 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 7 Feb 2014 15:42:35 +0000 (17:42 +0200)
lib/Gruntmaster/Page/Base.pm
lib/Gruntmaster/Page/Log.pm

index cf29eacc3c56962148f012739c16bc36b0260aee..cf7d2291587809652e8636c03d692692161ed4ae 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]");
@@ -147,11 +147,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.027654 seconds and 4 git commands to generate.