2011-03-09 55 views
1

當我使用WWW::Mechanize::Cached與默認值都工作正常。WWW ::機械化::緩存 - 問題

#!/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); 

我能做些什麼,使第二個例子工作?

回答

5

當驅動程序=>'內存'時,緩存將不會保留在磁盤上 - 將驅動程序更改爲'文件'或磁盤上的其他內容。

+0

因此腳本'Memory'的調用之間會丟失。我的想法是記憶會更快。 – 2011-03-09 16:01:46