Skip to content

Instantly share code, notes, and snippets.

@kimmel
Created January 5, 2012 14:54
Show Gist options
  • Save kimmel/1565583 to your computer and use it in GitHub Desktop.
Save kimmel/1565583 to your computer and use it in GitHub Desktop.
A simple script for testing the caching of a WWW::Mechanize module
#!/usr/bin/perl
use v5.10;
use warnings;
use strict;
use autodie;
use POSIX qw( strftime );
use CHI;
use WWW::Mechanize::Cached::GZip;
#use WWW::Mechanize::Cached;
# works perfectly:
#use WWW::Mechanize;
#use WWW::Mechanize::GZip;
say scalar strftime '%Y-%m-%d %H:%M:%S', localtime;
my $cache = CHI->new(
driver => 'File',
default_expires_in => '3 seconds',
expires_in => '3 seconds',
expires_on_backend => 1,
namespace => 'mech-test',
root_dir => '/tmp/perl-cache/',
);
#$cache->purge();
#$cache->clear();
#my $mech = WWW::Mechanize->new();
#my $mech = WWW::Mechanize::GZip->new();
#my $mech = WWW::Mechanize::Cached->new( cache => $cache );
my $mech = WWW::Mechanize::Cached::GZip->new( cache => $cache );
$mech->get('http://localhost:8081/nfo.php');
say $mech->content();
sleep 1;
say scalar strftime '%Y-%m-%d %H:%M:%S', localtime;
$mech->get('http://localhost:8081/nfo.php');
say $mech->content();
sleep 4;
say 'Waited 4 seconds';
say scalar strftime '%Y-%m-%d %H:%M:%S', localtime;
$mech->get('http://localhost:8081/nfo.php');
say $mech->content();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment