summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Controller/Map.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-01-04 23:28:47 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-01-04 23:28:47 +0100
commit45f4e39216d05217de9341bd991860d1cc95a3d5 (patch)
tree083d055f5a9878d0002a5756fb0ae46229965305 /lib/DBInfoscreen/Controller/Map.pm
parent3d22c00120518f8c5207fe1049a00506091cd43c (diff)
cache transport.rest requests
Diffstat (limited to 'lib/DBInfoscreen/Controller/Map.pm')
-rw-r--r--lib/DBInfoscreen/Controller/Map.pm15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm
index b22c5ea..df749bf 100644
--- a/lib/DBInfoscreen/Controller/Map.pm
+++ b/lib/DBInfoscreen/Controller/Map.pm
@@ -9,8 +9,16 @@ chomp $dbf_version;
sub get_hafas_polyline {
my ( $ua, $cache, $trip_id, $line ) = @_;
+ my $url
+ = "https://2.db.transport.rest/trips/${trip_id}?lineName=${line}&polyline=true";
+
+ if ( my $content = $cache->thaw($url) ) {
+ return $content;
+ }
+
$ua->request_timeout(2);
- #say "https://2.db.transport.rest/trips/${trip_id}?lineName=${line}&polyline=true";
+
+ #say $url;
my $res
= $ua->get(
"https://2.db.transport.rest/trips/${trip_id}?lineName=${line}&polyline=true"
@@ -32,11 +40,14 @@ sub get_hafas_polyline {
#}
}
- return {
+ my $ret = {
name => $json->{line}{name} // '?',
polyline => [@coordinate_list],
stopovers => $json->{stopovers},
};
+
+ $cache->freeze( $url, $ret );
+ return $ret;
}
sub route {