|
diff --git a/webapp/perl/cpanfile b/webapp/perl/cpanfile |
|
index e3d6103..944b12e 100644 |
|
--- a/webapp/perl/cpanfile |
|
+++ b/webapp/perl/cpanfile |
|
@@ -2,3 +2,6 @@ requires 'Kossy' => '0.12'; |
|
requires 'DBIx::Sunny' => '0.17'; |
|
requires 'DBD::mysql' => '4.022'; |
|
requires 'Starman' => '0.3003'; |
|
+requires 'Starlet'; |
|
+requires 'Cache::Memory::Simple'; |
|
+ |
|
diff --git a/webapp/perl/lib/Isucon2.pm b/webapp/perl/lib/Isucon2.pm |
|
index 4b4121c..e27a84a 100644 |
|
--- a/webapp/perl/lib/Isucon2.pm |
|
+++ b/webapp/perl/lib/Isucon2.pm |
|
@@ -7,6 +7,7 @@ use Kossy; |
|
|
|
use DBIx::Sunny; |
|
use JSON 'decode_json'; |
|
+use Cache::Memory::Simple; |
|
|
|
our $VERSION = '0.01'; |
|
|
|
@@ -54,7 +55,18 @@ filter 'recent_sold' => sub { |
|
} |
|
}; |
|
|
|
-get '/' => [qw(recent_sold)] => sub { |
|
+my $cache = Cache::Memory::Simple->new(); |
|
+filter 'page_cache' => sub { |
|
+ my ($app) = @_; |
|
+ sub { |
|
+ my ($self, $c) = @_; |
|
+ $cache->get_or_set($c->req->uri, sub { |
|
+ $app->($self, $c); |
|
+ },0.9); |
|
+ }; |
|
+}; |
|
+ |
|
+get '/' => [qw(page_cache recent_sold)] => sub { |
|
my ($self, $c) = @_; |
|
my $rows = $self->dbh->select_all( |
|
'SELECT * FROM artist ORDER BY id', |
|
@@ -62,7 +74,7 @@ get '/' => [qw(recent_sold)] => sub { |
|
$c->render('index.tx', { artists => $rows }); |
|
}; |
|
|
|
-get '/artist/:artistid' => [qw(recent_sold)] => sub { |
|
+get '/artist/:artistid' => [qw(page_cache recent_sold)] => sub { |
|
my ($self, $c) = @_; |
|
my $artist = $self->dbh->select_row( |
|
'SELECT id, name FROM artist WHERE id = ? LIMIT 1', |
|
@@ -87,7 +99,7 @@ get '/artist/:artistid' => [qw(recent_sold)] => sub { |
|
}); |
|
}; |
|
|
|
-get '/ticket/:ticketid' => [qw(recent_sold)] => sub { |
|
+get '/ticket/:ticketid' => [qw(page_cache recent_sold)] => sub { |
|
my ($self, $c) = @_; |
|
my $ticket = $self->dbh->select_row( |
|
'SELECT t.*, a.name AS artist_name FROM ticket t INNER JOIN artist a ON t.artist_id = a.id WHERE t.id = ? LIMIT 1', |