当我使用带有默认值的WWW::Mechanize::Cached时,一切正常。
#!/usr/bin/env perl
use warnings;
use 5.012;
use WWW::Mechanize::Cached;
my $uri = 'http://www.some_address';
my $mech = WWW::Mechanize::Cached->new();
$mech->show_progress( 1 );
$mech->get( $uri );
但是当我尝试变得聪明并选择自己的论点时,缓存似乎不起作用:每次运行脚本时,我都会遇到网络流量并且没有及时获得。
#!/usr/bin/env perl
use warnings;
use 5.012;
use Cwd qw(realpath);
use WWW::Mechanize::Cached;
use CHI;
my $uri = 'http://www.some_address';
my $cache = CHI->new( namespace => realpath($0), driver => 'Memory',
expires_in => '60 min', expires_variance => 0.25, global => 1 );
my $mech = WWW::Mechanize::Cached->new( cache => $cache );
$mech->show_progress( 1 );
$mech->get( $uri );
我该怎么做才能使第二个示例起作用?