LWP::UserAgent::Caching - HTTP::Casing based UserAgent, finally done right
use LWP::UserAgent::Caching; my $cache = CHI->new( driver => 'File', root_dir => '/tmp/LWP_UserAgent_Caching', file_extension => '.cache', l1_cache => { driver => 'Memory', global => 1, max_size => 1024*1024 }, ); my $ua = LWP::UserAgent::Caching->new( http_caching => { cache => $cache, type => 'private', request_directives => ( 'max-age=86400', # 24hrs 'min-fresh=60', # not over due within the next minute ), }, # more LWP::UserAgent options ); my $rqst = HTTP::Request->new( GET => 'http://example.com' ); $rqst->header( cache_control => 'no-cache' ); # Oh... now we bypass it ? $rqst->header( accept_language => 'nl, en-GB; q=0.9, en; 0.8, *' ); my $resp = $ua->request($rqst);
LWP::UserAgent::Caching gives you RFC compliant caching. It respects the old HTTP/1 headerfields like 'Expires' but also implements the HTTP/1.1 'Cache-Control' directives.
LWP::UserAgent::Caching
Unlike many other cachng useragents, this one does actually invalidate the cache after a non-error response returned by a non-safe request (like DELETE).
Since it's a subclass of the standard LWP::UserAgent, it inherits all those. In this module we also implemented the shortcuts from HTTP::Request::Common so that they will not call the parent class
HTTP::Caching The RFC 7234 compliant brains - DO NEVER USE THAT MODULE DIRECTLY
To install LWP::UserAgent::Caching, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LWP::UserAgent::Caching
CPAN shell
perl -MCPAN -e shell install LWP::UserAgent::Caching
For more information on module installation, please visit the detailed CPAN module installation guide.