diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 5f7bbd16..106f395b 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -244,6 +244,7 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) { # Give Hydra binary caches a very low priority (lower than the # static binary cache http://nixos.org/binary-cache). "Priority: 100\n"; + setCacheHeaders($c, 365 * 24 * 60 * 60); $c->forward('Hydra::View::Plain'); } @@ -260,6 +261,7 @@ sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) { $c->response->content_type('text/plain'); $c->stash->{plain}->{data} = "does not exist\n"; $c->forward('Hydra::View::Plain'); + setCacheHeaders($c, 60 * 60); return; } diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 82fe939c..d4ede730 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -28,6 +28,7 @@ our @EXPORT = qw( showJobName showStatus getResponsibleAuthors + setCacheHeaders ); @@ -305,4 +306,12 @@ sub getResponsibleAuthors { } +# Set HTTP headers for the Nix binary cache. +sub setCacheHeaders { + my ($c, $expiration) = @_; + $c->response->headers->expires(time + $expiration); + delete $c->response->cookies->{hydra_session}; +} + + 1; diff --git a/src/lib/Hydra/View/NARInfo.pm b/src/lib/Hydra/View/NARInfo.pm index b2532500..53e90356 100644 --- a/src/lib/Hydra/View/NARInfo.pm +++ b/src/lib/Hydra/View/NARInfo.pm @@ -5,6 +5,7 @@ use base qw/Catalyst::View/; use File::Basename; use Nix::Store; use Nix::Crypto; +use Hydra::Helper::CatalystUtils; sub process { my ($self, $c) = @_; @@ -39,6 +40,8 @@ sub process { $info .= "Signature: 1;$keyName;$sig\n"; } + setCacheHeaders($c, 24 * 60 * 60); + $c->response->body($info); return 1; diff --git a/src/lib/Hydra/View/NixNAR.pm b/src/lib/Hydra/View/NixNAR.pm index af1a5367..4b2160ac 100644 --- a/src/lib/Hydra/View/NixNAR.pm +++ b/src/lib/Hydra/View/NixNAR.pm @@ -2,6 +2,7 @@ package Hydra::View::NixNAR; use strict; use base qw/Catalyst::View/; +use Hydra::Helper::CatalystUtils; sub process { my ($self, $c) = @_; @@ -14,6 +15,8 @@ sub process { open $fh, "nix-store --dump '$storePath' | bzip2 |"; + setCacheHeaders($c, 365 * 24 * 60 * 60); + $c->response->body($fh); return 1;