Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make /source caching a little smarter and longer
  • Loading branch information
ranguard committed May 18, 2015
1 parent de32f54 commit 1304cfb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app.psgi
Expand Up @@ -172,6 +172,7 @@ else {
{
my $hour_ttl = 60 * 60;
my $day_ttl = $hour_ttl * 24;
my $year_ttl = $day_ttl * 365;

$app = builder {

Expand All @@ -193,12 +194,17 @@ else {
'Cache-Control' => "max-age=${hour_ttl}",
];

# Tell fastly to cache /source/ for a day
enable_if { $_[0]->{PATH_INFO} =~ m{^/source} } 'Headers', set => [
'Surrogate-Control' => "max-age=${day_ttl}",
# Tell fastly to cache, most of /source/
# /source/AUTHOR/anything e.g /source/ETHER/YAML-Tiny-1.67/
# But NO instructions for...
# /source/Foo::bar <- latest package (no 3rd /)
# /source/AUTHOR/ <- author package list, nothing after 3rd /
enable_if { $_[0]->{PATH_INFO} =~ m{^/source/.+/.+} } 'Headers', set => [
'Surrogate-Control' => "max-age=${year_ttl}",
'Surrogate-Key' => 'source',

# Tell the user's browser to cache for an hour
# Tell the user's browser to cache for an hour,
# incase the regex isn't quite right!
'Cache-Control' => "max-age=${hour_ttl}",
];

Expand Down

0 comments on commit 1304cfb

Please sign in to comment.