From 135021898f973475bd62edbe9ddbd382c772c3d3 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 13 Aug 2024 20:56:05 +0200 Subject: carriage formation: store replies in main and only errors in realtime cache --- lib/DBInfoscreen/Helper/Wagonorder.pm | 18 +++++++++++++----- 1 file 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; } -- cgit v1.2.3