LWP::UserAgent::OfflineCache - a caching user agent
Version 0.02
This module will cache all GET requests to disk. It otherwise behaves the same as LWP::UserAgent.
Caching performs regardsless of any returned HTTP headers.
Simple example:
#!/usr/bin/perl -w use strict; use LWP::UserAgent::OfflineCache; my $ua = LWP::UserAgent::OfflineCache->new; print $ua->get("http://www.yahoo.com/index.html");
More advanced example
#!/usr/bin/perl -w use strict; use LWP::UserAgent::OfflineCache; use Log::Log4perl; my $logConf = q( log4perl.category.lwp.useragent.offlinecache = INFO, Screen log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.stderr = 0 log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout ); Log::Log4perl::init( \$logConf ); my $ua = LWP::UserAgent::OfflineCache->new(cache_dir=> 'cache', delay=>3, use_gzip=>1); # The same as my $ua = LWP::UserAgent::OfflineCache->new; print $ua->get("http://www.yahoo.com/index.html");
The LWP::UserAgent::OfflineCache is a class-wrapper for LWP::UserAgent.
LWP::UserAgent::OfflineCache
LWP::UserAgent
::OfflineCache module allows to use offline cache for debug and logging purpose.
Also by default ::OfflineCache tries to use 'Accept-Encoding' HTTP header for using less bandwidth.
Cached content stored as a files with names md5($url) in the specified directory.
In additional to standard LWP::UserAgent's options the following key/pairs values are available:
KEY DEFAULT ---------- ------------------ cache_dir cache (means './cache') delay 3 (seconds) use_gzip 1
Get directory where cached content stored as files with names as md5 hash from requested url.
Get/set delay in seconds after each request to the server. Default value is 3.
Get/set boolean flag for automatic usage of 'gzip' (HTTP::Message::decodable()) in 'Accept-Encoding' header. Switched on by default.
<cpan at 5thplane.com>
<gdm at savesources.com>
You can find documentation for this module with the perldoc command.
perldoc LWP::UserAgent::OfflineCache
Thanks to Luke Closs for an idea and perfect implementation of Net::Parliament::UserAgent module.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install LWP::UserAgent::OfflineCache, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LWP::UserAgent::OfflineCache
CPAN shell
perl -MCPAN -e shell install LWP::UserAgent::OfflineCache
For more information on module installation, please visit the detailed CPAN module installation guide.