summaryrefslogtreecommitdiff
path: root/cgi/index.pl
diff options
context:
space:
mode:
Diffstat (limited to 'cgi/index.pl')
-rw-r--r--cgi/index.pl24
1 files changed, 22 insertions, 2 deletions
diff --git a/cgi/index.pl b/cgi/index.pl
index 11f69a5..3051f94 100644
--- a/cgi/index.pl
+++ b/cgi/index.pl
@@ -1,9 +1,30 @@
#!/usr/bin/env perl
use Mojolicious::Lite;
+use Cache::File;
use File::ShareDir qw(dist_file);
use HTML::Template;
use Travel::Status::DE::DeutscheBahn;
+sub get_results_for {
+ my ($station) = @_;
+
+ my $cache = Cache::File->new(
+ cache_root => '/tmp/db-fake',
+ default_expires => '900 sec'
+ );
+
+ my $results = $cache->thaw($station);
+
+ if (not $results) {
+ my $status = Travel::Status::DE::DeutscheBahn->new( station => $station
+ );
+ $results = [$status->results];
+ $cache->freeze($station, $results);
+ }
+
+ return @{ $results };
+}
+
get '/' => sub {
my $self = shift;
my $station = $self->param('station');
@@ -18,13 +39,12 @@ get '/multi/:station' => sub {
my $station = $self->stash('station');
my @params;
- my $status = Travel::Status::DE::DeutscheBahn->new( station => $station );
my $template = HTML::Template->new(
filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ),
loop_context_vars => 1,
);
- for my $result ( $status->results ) {
+ for my $result ( get_results_for($station) ) {
push(
@params,
{