From: Marius Gavrilescu Date: Fri, 7 Feb 2014 15:57:36 +0000 (+0200) Subject: Merge cache-control changes from master X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=9e1979aeb2725b7548115832fa696393772340bd;hp=a8b4e6d36eacf5bf07279e99be91f6c228092c39;p=plack-app-gruntmaster.git Merge cache-control changes from master --- diff --git a/app.psgi b/app.psgi index 20092c9..5bed878 100644 --- 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'; diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index 8883cad..ee8a310 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -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 ] } diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm index 4773fec..9192d95 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -55,4 +55,6 @@ sub _generate{ $htc->param(prev => $page - 1) unless $page == 1; } +sub max_age { 5 } + 1