From f988d539bb3e41c52dcfd5cb1942261a14d77705 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 13 Aug 2021 14:55:52 +0200 Subject: marudor: cache negative replies --- lib/DBInfoscreen/Helper/Marudor.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/DBInfoscreen/Helper/Marudor.pm b/lib/DBInfoscreen/Helper/Marudor.pm index 91b34e3..cdc90f4 100644 --- a/lib/DBInfoscreen/Helper/Marudor.pm +++ b/lib/DBInfoscreen/Helper/Marudor.pm @@ -34,11 +34,13 @@ sub get_json_p { my $promise = Mojo::Promise->new; if ( my $content = $cache->thaw($url) ) { + $self->{log}->debug("marudor->get_json_p($url): cached"); + if ( $content->{error} ) { + return $promise->reject( $content->{error} ); + } return $promise->resolve($content); } - $self->{log}->debug("get_json_p($url)"); - $self->{user_agent}->request_timeout(5)->get_p( $url => $self->{header} ) ->then( sub { @@ -48,6 +50,7 @@ sub get_json_p { $self->{log}->debug( "marudor->get_json_p($url): HTTP $err->{code} $err->{message}" ); + $cache->freeze( $url, { error => $err->{message} } ); $promise->reject( "GET $url returned HTTP $err->{code} $err->{message}"); return; @@ -72,6 +75,7 @@ sub get_json_p { sub { my ($err) = @_; $self->{log}->debug("marudor->get_json_p($url): $err"); + $cache->freeze( $url, { error => $err } ); $promise->reject($err); return; } -- cgit v1.2.3