Issue #5: Implemented Cache::FastMmap as caching module.
This commit is contained in:
parent
a37f0bd317
commit
8aba2fdd8c
34
F1DataBot.pm
34
F1DataBot.pm
@ -12,6 +12,7 @@ use Encode;
|
||||
use FindBin;
|
||||
|
||||
# CPAN packages
|
||||
use Cache::FastMmap;
|
||||
use JSON;
|
||||
use Log::Log4perl;
|
||||
use YAML;
|
||||
@ -21,6 +22,12 @@ package F1DataBot;
|
||||
|
||||
# Constants and initalisations
|
||||
Log::Log4perl->init("$FindBin::Bin/log.conf");
|
||||
my $CACHE = Cache::FastMmap->new(
|
||||
share_file => '/tmp/f1_bot',
|
||||
serializer => 'json',
|
||||
unlink_on_exit => 0,
|
||||
expire_time => 86400,
|
||||
);
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
@ -186,12 +193,20 @@ sub statistics {
|
||||
my $StatIdentifier = $+{statidentifier};
|
||||
given ($StatIdentifier) {
|
||||
when ('standings') {
|
||||
my $Standings = json POST(
|
||||
my $Standings;
|
||||
if ( $CACHE->get('driver_standings') ) {
|
||||
$Standings = $CACHE->get('driver_standings');
|
||||
}
|
||||
else {
|
||||
$Standings = json POST(
|
||||
join( '/',
|
||||
( $Self->{URL}{Ergast}, 'current', 'driverStandings.json' )
|
||||
),
|
||||
{}
|
||||
);
|
||||
$CACHE->set('driver_standings', $Standings);
|
||||
}
|
||||
|
||||
my %DriverStandings;
|
||||
my $DriverStandingsFormatted = sprintf( "%2s %3s %-5s%7s\n",
|
||||
"#", "No.", "Code", "Points" );
|
||||
@ -235,16 +250,19 @@ sub statistics {
|
||||
my $StatIdentifier = $+{statidentifier};
|
||||
given ($StatIdentifier) {
|
||||
when ('standings') {
|
||||
my $Standings = json POST(
|
||||
join(
|
||||
'/',
|
||||
(
|
||||
$Self->{URL}{Ergast}, 'current',
|
||||
'constructorStandings.json'
|
||||
)
|
||||
my $Standings;
|
||||
if ( $CACHE->get('constructor_standings') ) {
|
||||
$Standings = $CACHE->get('constructor_standings');
|
||||
}
|
||||
else {
|
||||
$Standings = json POST(
|
||||
join( '/',
|
||||
( $Self->{URL}{Ergast}, 'current', 'constructorStandings.json' )
|
||||
),
|
||||
{}
|
||||
);
|
||||
$CACHE->set('constructor_standings', $Standings);
|
||||
}
|
||||
$Self->{LogObject}
|
||||
->info( 'statistics: Fetched standings are '
|
||||
. Dumper($Standings) );
|
||||
|
Loading…
Reference in New Issue
Block a user