fix caching fuckup introduced in 2e5a1b0a79
This commit is contained in:
parent
7bb1f4fea0
commit
879b3b3815
1 changed files with 14 additions and 8 deletions
|
@ -34,7 +34,7 @@ sub has_wagonorder_p {
|
||||||
my $cache = $self->{cache};
|
my $cache = $self->{cache};
|
||||||
my $promise = Mojo::Promise->new;
|
my $promise = Mojo::Promise->new;
|
||||||
|
|
||||||
if ( my $content = $cache->get($url) ) {
|
if ( my $content = $cache->get("HEAD $url") ) {
|
||||||
if ( $content eq 'n' ) {
|
if ( $content eq 'n' ) {
|
||||||
return $promise->reject;
|
return $promise->reject;
|
||||||
}
|
}
|
||||||
|
@ -48,18 +48,18 @@ sub has_wagonorder_p {
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( $tx->result->is_success ) {
|
if ( $tx->result->is_success ) {
|
||||||
$cache->set( $url, 'a' );
|
$cache->set( "HEAD $url", 'a' );
|
||||||
$promise->resolve('a');
|
$promise->resolve('a');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$cache->set( $url, 'n' );
|
$cache->set( "HEAD $url", 'n' );
|
||||||
$promise->reject;
|
$promise->reject;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
$cache->set( $url, 'n' );
|
$cache->set( "HEAD $url", 'n' );
|
||||||
$promise->reject;
|
$promise->reject;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -90,11 +90,17 @@ sub get_wagonorder_p {
|
||||||
->then(
|
->then(
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
my $body = decode( 'utf-8', $tx->res->body );
|
|
||||||
|
|
||||||
|
if ( $tx->result->is_success ) {
|
||||||
|
my $body = decode( 'utf-8', $tx->res->body );
|
||||||
my $json = JSON->new->decode($body);
|
my $json = JSON->new->decode($body);
|
||||||
$cache->freeze( $url, $json );
|
$cache->freeze( $url, $json );
|
||||||
$promise->resolve($json);
|
$promise->resolve($json);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $code = $tx->code;
|
||||||
|
$promise->reject("HTTP ${code}");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
)->catch(
|
)->catch(
|
||||||
|
|
Loading…
Reference in a new issue