WWW::Mechanize::Cached - Cache response to be polite
Version 1.34
use WWW::Mechanize::Cached; my $cacher = WWW::Mechanize::Cached->new; $cacher->get( $url ); # or, with your own Cache object use CHI; use WWW::Mechanize::Cached; my $cache = CHI->new( driver => 'File', root_dir => '/tmp/mech-example' ); my $mech = WWW::Mechanize::Cached->new( cache => $cache ); $mech->get("http://www.google.com");
Uses the Cache::Cache hierarchy to implement a caching Mech. This lets one perform repeated requests without hammering a server impolitely.
Repository: http://github.com/oalders/www-mechanize-cached/tree/master
Behaves like, and calls, WWW::Mechanize's new method. Any params, other than those explicitly listed here are passed directly to WWW::Mechanize's constructor.
new
You may pass in a cache => $cache_object if you wish. The $cache_object must have get() and set() methods like the Cache::Cache family.
cache => $cache_object
get()
set()
Cache::Cache
The default Cache object is set up with the following params:
my $cache_params = { default_expires_in => "1d", namespace => 'www-mechanize-cached', }; $cache = Cache::FileCache->new( $cache_params );
This should be fine if you only want to use a disk-based cache, you only want to cache results for 1 day and you're not in a shared hosting environment. If any of this presents a problem for you, you should pass in your own Cache object. These defaults will remain unchanged in order to maintain backwards compatibility.
For example, you may want to try something like this:
use WWW::Mechanize::Cached; use CHI; my $cache = CHI->new( driver => 'File', root_dir => '/tmp/mech-example' ); my $mech = WWW::Mechanize::Cached->new( cache => $cache ); $mech->get("http://www.google.com");
Most methods are provided by WWW::Mechanize. See that module's documentation for details.
Returns true if the current page is from the cache, or false if not. If it returns undef, then you don't have any current request.
undef
Iain Truskett for writing this in the first place.
It may sometimes seem as if it's not caching something. And this may well be true. It uses the HTTP request, in string form, as the key to the cache entries, so any minor changes will result in a different key. This is most noticable when following links as WWW::Mechanize adds a Referer header.
Referer
You can find documentation for this module with the perldoc command.
perldoc WWW::Mechanize::Cached
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/WWW-Mechanize-Cached
CPAN Ratings
http://cpanratings.perl.org/d/WWW-Mechanize-Cached
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Cached
Search CPAN
http://search.cpan.org/dist/WWW-Mechanize-Cached
This module is copyright Iain Truskett and Andy Lester, 2004. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.000 or, at your option, any later version of Perl 5 you may have available.
Iain Truskett <spoon@cpan.org>
Maintained from 2004 - July 2009 by Andy Lester <petdance@cpan.org>
Currently maintained by Olaf Alders <olaf@wundercounter.com>
WWW::Mechanize.
To install WWW::Mechanize::Cached, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mechanize::Cached
CPAN shell
perl -MCPAN -e shell install WWW::Mechanize::Cached
For more information on module installation, please visit the detailed CPAN module installation guide.