1

当我使用带有默认值的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 );

我该怎么做才能使第二个示例起作用?

4

1 回答 1

5

使用 driver => 'Memory',缓存不会保留在磁盘上 - 将驱动程序更改为 'File' 或磁盘上的其他内容。

于 2011-03-09T15:25:55.643 回答