WWW::Mechanize::Cached - 问题
当我使用带有默认值的 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 );
我该怎么做才能使第二个示例起作用?
When I use WWW::Mechanize::Cached with default values all works fine.
#!/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 );
But when I try to be smart and choose my own arguments, it seems the caching is not working: each time I run the script I have network-traffic and no gain in time.
#!/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 );
What could I do, to make the second example work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
带司机=> “内存”,缓存不会保留在磁盘上 - 将驱动程序更改为“文件”或磁盘上的其他内容。
With driver => 'Memory', the cache won't persist on disk -- change the driver to 'File' or something else that's on disk.