Skip to content

Commit

Permalink
cache content-type as well
Browse files Browse the repository at this point in the history
  • Loading branch information
robn committed Dec 23, 2015
1 parent b3ff856 commit 095417a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/TownCrier.pm
Expand Up @@ -39,12 +39,15 @@ my $cache = CHI->new(driver => 'FastMmap', cache_size => '10m');
sub cached (&) {
my ($s) = @_;
return sub {
content_type 'text/html';
my $expiry_key = "_expiry_".request->uri;
my $expires_in = $cache->get($expiry_key) // 1;
my $out = $cache->compute(request->uri, $expires_in, sub {
$cache->set($expiry_key, min($expires_in * 1.6, 3600));
$s->();
[$s->(), content_type()];
});
content_type $out->[1];
$out->[0];
};
}

Expand Down

0 comments on commit 095417a

Please sign in to comment.