summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen/Helper
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2024-08-13 20:56:05 +0200
committerBirte Kristina Friesel <birte.friesel@uos.de>2024-08-13 20:56:05 +0200
commit135021898f973475bd62edbe9ddbd382c772c3d3 (patch)
tree7a0592cd9ab36cbd2aa7ac1e61cb5a56bcd0f138 /lib/DBInfoscreen/Helper
parentf462b95adf2c18c9a734187b58281da258439db4 (diff)
carriage formation: store replies in main and only errors in realtime cache4.29.9
Diffstat (limited to 'lib/DBInfoscreen/Helper')
-rw-r--r--lib/DBInfoscreen/Helper/Wagonorder.pm18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/DBInfoscreen/Helper/Wagonorder.pm b/lib/DBInfoscreen/Helper/Wagonorder.pm
index eb5cd74..94eebb1 100644
--- a/lib/DBInfoscreen/Helper/Wagonorder.pm
+++ b/lib/DBInfoscreen/Helper/Wagonorder.pm
@@ -49,11 +49,19 @@ sub get_p {
'https://www.bahn.de/web/api/reisebegleitung/wagenreihung/vehicle-sequence',
join( '&', map { $_ . '=' . $param{$_} } keys %param ) );
- my $cache = $self->{realtime_cache};
-
my $promise = Mojo::Promise->new;
- if ( my $content = $cache->thaw($url) ) {
+ if ( my $content = $self->{main_cache}->thaw($url) ) {
+ $self->{log}->debug("wagonorder->get_p($url): cached");
+ if ( $content->{error} ) {
+ return $promise->reject(
+"GET $url: HTTP $content->{error}{code} $content->{error}{message} (cachd)"
+ );
+ }
+ return $promise->resolve( $content, \%param );
+ }
+
+ if ( my $content = $self->{realtime_cache}->thaw($url) ) {
$self->{log}->debug("wagonorder->get_p($url): cached");
if ( $content->{error} ) {
return $promise->reject(
@@ -78,7 +86,7 @@ sub get_p {
$self->{log}->debug(
"wagonorder->get_p($url): HTTP $err->{code} $err->{message}"
);
- $cache->freeze( $url, $json );
+ $self->{realtime_cache}->freeze( $url, $json );
$promise->reject("GET $url: HTTP $err->{code} $err->{message}");
return;
}
@@ -86,7 +94,7 @@ sub get_p {
$self->{log}->debug("wagonorder->get_p($url): OK");
my $json = $tx->res->json;
- $cache->freeze( $url, $json );
+ $self->{main_cache}->freeze( $url, $json );
$promise->resolve( $json, \%param );
return;
}