diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-09-28 13:42:49 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-09-28 13:42:49 +0200 |
commit | 248b692492c466a06aa0a7c9afb69137a7fc6200 (patch) | |
tree | 77988c1db7df52780d1a8ee3822d4e4d355d38eb /bin | |
parent | 5c26e3b6a426343e2b3f852311fe0028ab7d75b8 (diff) |
Cache efa replies by default
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/efa-m | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -16,6 +16,8 @@ use Travel::Status::DE::EFA; my $service = 'VRR'; my $efa_url; my $efa_encoding; +my $use_cache = 1; +my $cache; my ( $date, $time, $input_type, $list_lines, $offset, $relative_times ); my ( $full_routes, $filter_via, $show_jid ); my ( $timeout, $developer_mode ); @@ -54,6 +56,7 @@ GetOptions( 'u|efa-url=s' => \$efa_url, 'v|via=s' => \$filter_via, 'V|track-via=s' => \$filter_via, + 'cache!' => \$use_cache, 'version' => \&show_version, 'devmode' => \$developer_mode, @@ -67,6 +70,21 @@ if ( @ARGV < 1 or @ARGV > 2 ) { show_help(1); } +if ($use_cache) { + my $cache_path = ( $ENV{XDG_CACHE_HOME} // "$ENV{HOME}/.cache" ) . '/efa-m'; + eval { + require Cache::File; + $cache = Cache::File->new( + cache_root => $cache_path, + default_expires => '90 seconds', + lock_level => Cache::File::LOCK_LOCAL(), + ); + }; + if ($@) { + $cache = undef; + } +} + # --line=foo,bar support @edata_pre = split( qr{,}, join( q{,}, @edata_pre ) ); @grep_lines = split( qr{,}, join( q{,}, @grep_lines ) ); @@ -130,6 +148,7 @@ sub new_efa { my $res = Travel::Status::DE::EFA->new( service => $s, efa_url => $u, + cache => $cache, date => $date, developer_mode => $developer_mode, efa_encoding => $efa_encoding, |