Skip to content

Return the cache result if there is a cache hit #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

briandfoy
Copy link

This patches fixes a problem returning a cache result, and adds a test for that.

Consider this program, that looks up the same IP twice. The second one should pull from the cache:

use strict;
use warnings;

use Data::Dumper qw(Dumper);

use Geo::IPinfo;

my $ipinfo = Geo::IPinfo->new( $ENV{APP_IPINFO_TOKEN} );

my $info = $ipinfo->info( '151.101.130.132' );
print Dumper($info);

my $info = $ipinfo->info( '151.101.130.132' );
print Dumper($info);

The problem is that the cached value in get_info is reprocessed through Geo::Details::new, so gets an extra wrapper around it (second $VAR1):

$VAR1 = bless( {
                 'org' => 'AS54113 Fastly, Inc.',
                 'country_name' => 'United States',
                 'anycast' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),
                 'loc' => '37.7621,-122.3971',
                 'timezone' => 'America/Los_Angeles',
                 'country_currency' => {
                                         'symbol' => '$',
                                         'code' => 'USD'
                                       },
                 'latitude' => '37.7621',
                 'longitude' => '-122.3971',
                 'region' => 'California',
                 'is_eu' => undef,
                 'country' => 'US',
                 'postal' => '94107',
                 'country_flag' => {
                                     'emoji' => '🇺🇸',
                                     'unicode' => 'U+1F1FA U+1F1F8'
                                   },
                 'continent' => {
                                  'name' => 'North America',
                                  'code' => 'NA'
                                },
                 'ip' => '151.101.130.132',
                 'meta' => {
                             'from_cache' => 0,
                             'time' => 1741410971
                           },
                 'city' => 'San Francisco',
                 'country_flag_url' => 'https://cdn.ipinfo.io/static/images/countries-flags/US.svg'
               }, 'Geo::Details' );
$VAR1 = bless( {
                 '' => bless( {
                                'org' => 'AS54113 Fastly, Inc.',
                                'country_name' => 'United States',
                                'anycast' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),
                                'loc' => '37.7621,-122.3971',
                                'timezone' => 'America/Los_Angeles',
                                'country_currency' => {
                                                        'symbol' => '$',
                                                        'code' => 'USD'
                                                      },
                                'latitude' => '37.7621',
                                'longitude' => '-122.3971',
                                'region' => 'California',
                                'is_eu' => undef,
                                'country' => 'US',
                                'postal' => '94107',
                                'country_flag' => {
                                                    'emoji' => '🇺🇸',
                                                    'unicode' => 'U+1F1FA U+1F1F8'
                                                  },
                                'continent' => {
                                                 'name' => 'North America',
                                                 'code' => 'NA'
                                               },
                                'ip' => '151.101.130.132',
                                'meta' => {
                                            'from_cache' => 1,
                                            'time' => 1741410971
                                          },
                                'city' => 'San Francisco',
                                'country_flag_url' => 'https://cdn.ipinfo.io/static/images/countries-flags/US.svg'
                              }, 'Geo::Details' )
               }, 'Geo::Details' );```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant