Skip to content
Snippets Groups Projects
Unverified Commit 713715b0 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

hafas-m: Use cache if Cache::File is available; add --no-cache option

parent baa8c633
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,8 @@ my $num_results = 30;
my $types = q{};
my $developer_mode;
my $via;
my $use_cache = 1;
my $cache;
my ( $json_output, $raw_json_output );
my ( $list_services, $service );
my ( @excluded_mots, @exclusive_mots );
......@@ -47,6 +49,7 @@ GetOptions(
't|time=s' => \$time,
'v|via=s' => \$via,
'V|version' => \&show_version,
'cache!' => \$use_cache,
'devmode' => \$developer_mode,
'json' => \$json_output,
'raw-json' => \$raw_json_output,
......@@ -71,9 +74,26 @@ if ($list_services) {
exit 0;
}
if ($use_cache) {
my $cache_path = ( $ENV{XDG_CACHE_HOME} // "$ENV{HOME}/.cache" )
. '/Travel-Status-DE-HAFAS';
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;
}
}
parse_mot_options();
my %opt = (
cache => $cache,
excluded_mots => \@excluded_mots,
exclusive_mots => \@exclusive_mots,
station => shift || show_help(1),
......@@ -804,6 +824,13 @@ The I<mot> types depend on the used service. Use C<< -m help >> to list them.
Request up to I<count> results. Default: 30.
=item B<--no-cache>
If the Cache::File module is available, server replies are cached in
F<~/.cache/Travel-Status-DE-HAFAS> (or a path relative to C<$XDG_CACHE_HOME>,
if set) for 90 seconds. Use this option to disable caching. You can also use
B<--cache> to re-enable it.
=item B<--raw-json>
Print unprocessed HAFAS response as JSON and exit.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment