diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-02-22 14:42:42 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-02-22 14:42:42 +0100 |
commit | 75cd6a759070024facc555eb27bfb3cf78d6635a (patch) | |
tree | 6bd3ac814f656c716f889daf9b90e2732bf3f9fb | |
parent | efa19e5a53099bec411f1dbf7566f79d884026c1 (diff) |
increase default cache lifetime, set it based on the used API type
-rw-r--r-- | index.pl | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -44,16 +44,10 @@ sub log_api_access { } sub get_results { - my ( $backend, $city, $stop, $expiry ) = @_; + my ( $backend, $city, $stop ) = @_; my $sub_backend; - $expiry ||= 150; - - my $cache = Cache::File->new( - cache_root => $ENV{VRRFAKEDISPLAY_CACHE} // '/tmp/vrr-fakedisplay', - default_expires => "${expiry} sec", - lock_level => Cache::File::LOCK_LOCAL(), - ); + my $expiry = 200; # legacy values if ( not defined $backend or $backend eq 'vrr' ) { @@ -80,6 +74,19 @@ sub get_results { } } + if ( $backend eq 'hafas' ) { + $expiry = 120; + } + elsif ( $backend eq 'aseag' ) { + $expiry = 120; + } + + my $cache = Cache::File->new( + cache_root => $ENV{VRRFAKEDISPLAY_CACHE} // '/tmp/vrr-fakedisplay', + default_expires => "${expiry} sec", + lock_level => Cache::File::LOCK_LOCAL(), + ); + my $sstr = ("${backend} _ ${stop} _ ${city}"); $sstr =~ tr{a-zA-Z0-9}{_}c; @@ -240,8 +247,7 @@ sub get_filtered_departures { my ( @grep_line, @grep_platform, @filtered_results ); - my $data = get_results( $opt{backend}, $opt{city}, $opt{stop}, - $opt{cache_expiry} ); + my $data = get_results( $opt{backend}, $opt{city}, $opt{stop} ); my $results = $data->{results}; @@ -434,7 +440,6 @@ sub render_json { city => $self->stash('city') // q{}, stop => $self->stash('stop'), backend => scalar $self->param('backend'), - cache_expiry => 120, filter_line => scalar $self->param('line'), filter_platform => scalar $self->param('platform'), hide_regional => 0, |