Skip to content

Commit 444728b

Browse files
committed
Add cdn caching to search (most hit end point, will do background revalidation and serve from cache if error)
1 parent 218a939 commit 444728b

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

lib/MetaCPAN/Web/Controller/About.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ sub meta_hack : Local : Args(0) {
4040

4141
sub resources : Local : Args(0) {
4242
my ( $self, $c ) = @_;
43+
$c->browser_max_age('1y');
44+
$c->cdn_max_age('1y');
4345
$c->res->redirect( '/about/contact', 301 );
4446
$c->detach;
4547
}

lib/MetaCPAN/Web/Controller/Pod.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sub view : Private {
4040
my $release = $c->stash->{release};
4141

4242
if ( $data->{directory} ) {
43+
$c->cdn_max_age('1y');
4344
$c->res->redirect( $c->uri_for( '/source', @path ), 301 );
4445
$c->detach;
4546
}

lib/MetaCPAN/Web/Controller/Release.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ sub view : Private {
6565

6666
my $release = $data->{release};
6767

68-
$c->browser_max_age('1h');
68+
$c->browser_max_age('1d');
6969
$c->res->last_modified( $release->{date} );
7070
$c->cdn_max_age('1y');
7171
$c->add_dist_key( $release->{distribution} );

lib/MetaCPAN/Web/Controller/Root.pm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ Attempt to render a view, if needed.
113113
sub end : ActionClass('RenderView') {
114114
my ( $self, $c ) = @_;
115115

116-
# This will only affect if `cdn_max_age` has been set.
117-
# https://www.fastly.com/documentation/guides/concepts/edge-state/cache/stale/
118-
# If it has then do revalidation in the background
116+
# This will only affect if `cdn_max_age` has been set.
117+
# https://www.fastly.com/documentation/guides/concepts/edge-state/cache/stale/
118+
# If it has then do revalidation in the background
119119
$c->cdn_stale_while_revalidate('1d');
120+
120121
# And if there is still an error serve from cache
121122
$c->cdn_stale_if_error('1y');
122123

lib/MetaCPAN/Web/Controller/Search.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ sub index : Path : Args(0) {
1616
my $page = $req->page;
1717
my $page_size = $req->get_page_size(20);
1818

19+
# Cache searches as this is where most traffic hits
20+
$c->cdn_max_age('1d');
21+
1922
# Redirect back to main page if search query is empty irrespective of
2023
# whether we're feeling lucky or not.
2124
unless ( $req->param('q') ) {
25+
$c->browser_max_age('1w');
2226
$c->res->redirect('/');
2327
$c->detach;
2428
}

0 commit comments

Comments
 (0)