Commit 13f462df authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

make cache data easier to extend

parent 1725719f
Loading
Loading
Loading
Loading
+17 −9
Original line number Original line Diff line number Diff line
@@ -30,9 +30,9 @@ sub get_results_for {


	my $cache_str = "${backend}_${cstation}";
	my $cache_str = "${backend}_${cstation}";


	my $results = $cache->thaw($cache_str);
	my $data = $cache->thaw($cache_str);


	if ( not $results ) {
	if ( not $data ) {
		if ( $backend eq 'iris' ) {
		if ( $backend eq 'iris' ) {


			# requests with DS100 codes should be preferred (they avoid
			# requests with DS100 codes should be preferred (they avoid
@@ -49,20 +49,26 @@ sub get_results_for {
				serializable => 1,
				serializable => 1,
				%opt
				%opt
			);
			);
			$results = [ [ $status->results ], $status->errstr ];
			$data = {
			$cache->freeze( $cache_str, $results );
				results => [ $status->results ],
				errstr  => $status->errstr,
			};
			$cache->freeze( $cache_str, $data );
		}
		}
		else {
		else {
			my $status = Travel::Status::DE::DeutscheBahn->new(
			my $status = Travel::Status::DE::DeutscheBahn->new(
				station => $station,
				station => $station,
				%opt
				%opt
			);
			);
			$results = [ [ $status->results ], $status->errstr ];
			$data = {
			$cache->freeze( $cache_str, $results );
				results => [ $status->results ],
				errstr  => $status->errstr,
			};
			$cache->freeze( $cache_str, $data );
		}
		}
	}
	}


	return @{$results};
	return $data;
}
}


helper 'is_important' => sub {
helper 'is_important' => sub {
@@ -182,8 +188,10 @@ sub handle_request {
	}
	}


	my @departures;
	my @departures;
	my ( $results_ref, $errstr ) = get_results_for( $backend, $station, %opt );
	my $data        = get_results_for( $backend, $station, %opt );
	my @results = @{$results_ref};
	my $results_ref = $data->{results};
	my $errstr      = $data->{errstr};
	my @results     = @{$results_ref};


	if ( not @results and $template ~~ [qw[json marudor_v1 marudor]] ) {
	if ( not @results and $template ~~ [qw[json marudor_v1 marudor]] ) {
		$self->res->headers->access_control_allow_origin('*');
		$self->res->headers->access_control_allow_origin('*');