From 43413c5643466c46acc10be113a4e41d6c8f8c5e Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Wed, 13 Mar 2024 16:33:44 -0400 Subject: [PATCH] Latest Utils.pm from VWF --- lib/Geo/Coder/Free/Utils.pm | 62 +++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/Geo/Coder/Free/Utils.pm b/lib/Geo/Coder/Free/Utils.pm index 3590eadf..a5ad1239 100644 --- a/lib/Geo/Coder/Free/Utils.pm +++ b/lib/Geo/Coder/Free/Utils.pm @@ -25,7 +25,7 @@ sub create_disc_cache { my $logger = $args{'logger'}; my $driver = $config->{disc_cache}->{driver}; unless(defined($driver)) { - my $root_dir = $args{'root_dir'} || $config->{disc_cache}->{root_dir}; + my $root_dir = $args{'root_dir'} || $ENV{'root_dir'} || $config->{disc_cache}->{root_dir} || $config->{'root_dir'}; throw Error::Simple('root_dir is not optional') unless($root_dir); if($logger) { @@ -45,10 +45,11 @@ sub create_disc_cache { namespace => $args{'namespace'} ); - if($logger) { - $chi_args{'on_set_error'} = 'log'; - $chi_args{'on_get_error'} = 'log'; - } + # Don't do this because it takes a lot of complex configuration + # if($logger) { + # $chi_args{'on_set_error'} = 'log'; + # $chi_args{'on_get_error'} = 'log'; + # } if($config->{disc_cache}->{server}) { my @servers; @@ -67,29 +68,28 @@ sub create_disc_cache { } } $chi_args{'servers'} = \@servers; - } elsif(($driver ne 'DBI') && ($driver ne 'Null')) { - $chi_args{'root_dir'} = $args{'root_dir'} || $config->{disc_cache}->{root_dir}; - throw Error::Simple('root_dir is not optional') unless($chi_args{'root_dir'}); - if($logger) { - $logger->debug("root_dir: $chi_args{root_dir}"); + } elsif($driver eq 'DBI') { + # Use the cache connection details in the configuration file + $chi_args{'dbh'} = DBI->connect($config->{disc_cache}->{connect}); + if(!defined($chi_args{'dbh'})) { + if($logger) { + $logger->error($DBI::errstr); + } + throw Error::Simple($DBI::errstr); } - } - if($driver eq 'Redis') { + $chi_args{'create_table'} = 1; + } elsif($driver eq 'Redis') { my %redis_options = ( reconnect => 60, every => 1_000_000 ); $chi_args{'redis_options'} = \%redis_options; - } elsif($driver eq 'DBI') { - # Use the cache connection details in the configuration file - $chi_args{'dbh'} = DBI->connect($config->{disc_cache}->{connect}); - if(!defined($chi_args{'dbh'})) { - if($logger) { - $logger->error($DBI::errstr); - } - throw Error::Simple($DBI::errstr); - } - $chi_args{'create_table'} = 1; + } elsif($driver ne 'Null') { + $chi_args{'root_dir'} = $args{'root_dir'} || $config->{disc_cache}->{root_dir}; + throw Error::Simple('root_dir is not optional') unless($chi_args{'root_dir'}); + if($logger) { + $logger->debug("root_dir: $chi_args{root_dir}"); + } } return CHI->new(%chi_args); } @@ -108,7 +108,7 @@ sub create_memory_cache { } # return CHI->new(driver => 'Memcached', servers => [ '127.0.0.1:11211' ], namespace => $args{'namespace'}); # return CHI->new(driver => 'File', root_dir => '/tmp/cache', namespace => $args{'namespace'}); - return CHI->new(driver => 'SharedMem', size => 16 * 1024, max_size => 16 * 1024, shmkey => 98766789, namespace => $args{'namespace'}); + return CHI->new(driver => 'SharedMem', max_size => 1024, shm_size => 16 * 1024, shm_key => 98766789, namespace => $args{'namespace'}); } if($logger) { $logger->debug('memory cache via ', $config->{memory_cache}->{driver}, ', namespace: ', $args{'namespace'}); @@ -144,18 +144,20 @@ sub create_memory_cache { } $chi_args{'servers'} = \@servers; } elsif($driver eq 'SharedMem') { - $chi_args{'shmkey'} = $args{'shmkey'} || $config->{memory_cache}->{shmkey}; - if(my $size = ($args{'size'} || $config->{'memory_cache'}->{'size'})) { - $chi_args{'max_size'} = $chi_args{'size'} = $size; + $chi_args{'shm_key'} = $args{'shm_key'} || $config->{memory_cache}->{shm_key}; + if(my $shm_size = ($args{'shm_size'} || $config->{'memory_cache'}->{'shm_size'})) { + $chi_args{'shm_size'} = $shm_size; + } + if(my $max_size = ($args{'max_size'} || $config->{'memory_cache'}->{'max_size'})) { + $chi_args{'max_size'} = $max_size; } - } elsif(($driver ne 'Null') && ($driver ne 'Memory') && ($driver ne 'SharedMem')) { - $chi_args{'root_dir'} = $args{'root_dir'} || $config->{memory_cache}->{root_dir}; + } elsif(($driver ne 'Null') && ($driver ne 'Memory')) { + $chi_args{'root_dir'} = $args{'root_dir'} || $config->{memory_cache}->{root_dir} || $config->{'root_dir'}; throw Error::Simple('root_dir is not optional') unless($chi_args{'root_dir'}); if($logger) { $logger->debug("root_dir: $chi_args{root_dir}"); } - } - if($driver eq 'Redis') { + } elsif($driver eq 'Redis') { my %redis_options = ( reconnect => 60, every => 1_000_000