Skip to content

Commit

Permalink
Merge pull request #1201 from CPAN-API/leo/fastly_surrogate
Browse files Browse the repository at this point in the history
Leo/fastly surrogate
  • Loading branch information
oalders committed May 22, 2014
2 parents 57e1bbe + aaed55b commit 2c8227d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
20 changes: 20 additions & 0 deletions app.psgi
Expand Up @@ -16,9 +16,11 @@ use FindBin;
use lib "$FindBin::RealBin/lib";
use File::Path ();
use MetaCPAN::Web;
use Plack::Builder;
use Plack::App::File;
use Plack::App::URLMap;
use Plack::Middleware::Assets;
use Plack::Middleware::Headers;
use Plack::Middleware::Runtime;
use Plack::Middleware::MCLess;
use Plack::Middleware::ReverseProxy;
Expand Down Expand Up @@ -109,8 +111,26 @@ if ( !$ENV{PLACK_ENV} || $ENV{PLACK_ENV} ne 'development' ) {
)
],
);

}

# Handle surrogate (fastly caching)
my $hour_ttl = 60 * 60;
my $day_ttl = $hour_ttl * 24;

$app = builder {

# Tell fastly to cache _asset and _asset_less for a day
enable_if { $_[0]->{PATH_INFO} =~ m{^/_asset} } 'Headers',
set => [ 'Surrogate-Control' => "max-age=${day_ttl}" ];

# Tell fastly to cache /static/ for an hour
enable_if { $_[0]->{PATH_INFO} =~ m{^/static} } 'Headers',
set => [ 'Surrogate-Control' => "max-age=${hour_ttl}" ];

$app;
};

Plack::Middleware::ReverseProxy->wrap(
sub {
my $env = shift;
Expand Down
Empty file added bin/purge.pl
Empty file.
1 change: 1 addition & 0 deletions cpanfile
Expand Up @@ -49,6 +49,7 @@ requires 'PerlIO::gzip';
requires 'Plack::Middleware::Assets';
requires 'Plack::Middleware::ReverseProxy';
requires 'Plack::Middleware::Runtime';
requires 'Plack::Middleware::Headers';
requires 'Plack::Middleware::ServerStatus::Lite';
requires 'Plack::Middleware::Session';
requires 'Plack::Middleware::Session::Cookie';
Expand Down
45 changes: 22 additions & 23 deletions cpanfile.snapshot
Expand Up @@ -230,17 +230,6 @@ DISTRIBUTIONS
Module::Metadata 0
strict 0
warnings 0
CPAN-Meta-Requirements-2.125
pathname: D/DA/DAGOLDEN/CPAN-Meta-Requirements-2.125.tar.gz
provides:
CPAN::Meta::Requirements 2.125
requirements:
Carp 0
ExtUtils::MakeMaker 6.17
Scalar::Util 0
strict 0
version 0.77
warnings 0
CPAN-Meta-YAML-0.012
pathname: D/DA/DAGOLDEN/CPAN-Meta-YAML-0.012.tar.gz
provides:
Expand Down Expand Up @@ -988,7 +977,6 @@ DISTRIBUTIONS
requirements:
DateTime 0.17
HTTP::Date 1.44
Module::Build 0.36
Test::More 0.47
DateTime-Format-ISO8601-0.08
pathname: J/JH/JHOBLITT/DateTime-Format-ISO8601-0.08.tar.gz
Expand Down Expand Up @@ -1502,7 +1490,7 @@ DISTRIBUTIONS
DateTime::Locale::zu_ZA undef
requirements:
List::MoreUtils 0
Module::Build 0.36
Module::Build 0
Params::Validate 0.91
perl 5.006
DateTime-TimeZone-1.65
Expand Down Expand Up @@ -2678,15 +2666,6 @@ DISTRIBUTIONS
JSON::PP 2.27202
Test::More 0.88
Test::Without::Module 0.17
JSON-PP-2.27203
pathname: M/MA/MAKAMAKA/JSON-PP-2.27203.tar.gz
provides:
JSON::PP 2.27203
JSON::PP::Boolean 2.27203
JSON::PP::IncrParser 2.27203
requirements:
ExtUtils::MakeMaker 0
Test::More 0
JSON-XS-3.01
pathname: M/ML/MLEHMANN/JSON-XS-3.01.tar.gz
provides:
Expand Down Expand Up @@ -3945,6 +3924,20 @@ DISTRIBUTIONS
overload 0
parent 0
strict 0
Perl-Tidy-20140328
pathname: S/SH/SHANCOCK/Perl-Tidy-20140328.tar.gz
provides:
Perl::Tidy 20140328
Perl::Tidy::DevNull 20140328
Perl::Tidy::Diagnostics 20140328
Perl::Tidy::HtmlWriter 20140328
Perl::Tidy::IOScalar 20140328
Perl::Tidy::IOScalarArray 20140328
Perl::Tidy::LineSink 20140328
Perl::Tidy::LineSource 20140328
Perl::Tidy::Logger 20140328
requirements:
ExtUtils::MakeMaker 0
PerlIO-gzip-0.18
pathname: N/NW/NWCLARK/PerlIO-gzip-0.18.tar.gz
provides:
Expand Down Expand Up @@ -4091,6 +4084,13 @@ DISTRIBUTIONS
parent 0
strict 0
warnings 0
Plack-Middleware-Headers-0.11
pathname: V/VO/VOJ/Plack-Middleware-Headers-0.11.tar.gz
provides:
Plack::Middleware::Headers 0.11
requirements:
ExtUtils::MakeMaker 6.30
Plack::Middleware 0
Plack-Middleware-MethodOverride-0.10
pathname: D/DW/DWHEELER/Plack-Middleware-MethodOverride-0.10.tar.gz
provides:
Expand Down Expand Up @@ -4579,7 +4579,6 @@ DISTRIBUTIONS
provides:
Test::Exception 0.32
requirements:
Module::Build 0.38
Sub::Uplevel 0.18
Test::Builder 0.7
Test::Builder::Tester 1.07
Expand Down

0 comments on commit 2c8227d

Please sign in to comment.