MooseX::CachingProxy - Send LWP requests through a caching proxy server
package MyDownloader; use Moose; use WWW::Mechanize; with 'MooseX::CachingProxy'; has url => (is => 'ro', isa => 'Str', default => 'http://example.com'); sub BUILD {$self->start_caching_proxy} # this method retrieves web pages via the caching proxy sub get_files { my $response = WWW::Mechanize->new()->get('http://example.com'); } # this method retrieves web pages directly from example.com sub get_fresh_files { $self->stop_caching_proxy; my $response = WWW::Mechanize->new()->get('http://example.com'); $self->start_caching_proxy; }
This is a Moose role that allows you to easily cache responses from remote servers. For this to work, use either LWP or a library that uses LWP (like WWW::Mechanize).
The implementation is a mashup of Plack::App::Proxy, Plack::Middleware::Cache, and LWP::Protocol::PSGI. It intercepts any LWP requests made and routes them to a PSGI app. The PSGI app will return a cached response if available or send the request on to the intended server.
This role requires a 'url' attribute or method.
Required. All requests are proxied to this server. Example: http://example.com.
Optional. The directory on the local filesystem where responses are cached. The default location is '/tmp/caching-proxy'.
Start intercepting LWP requests with a caching proxy server
Add an option to remove the cache directory?
Thanks to Foxtons Ltd for providing the opportunity to write and release the original version of this module.
Plack::App::Proxy, Plack::Middleware::Cache, LWP::Protocol::PSGI
Eric Johnson <cpan at iijo dot org>
This software is copyright (c) 2012 by Eric Johnson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooseX::CachingProxy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::CachingProxy
CPAN shell
perl -MCPAN -e shell install MooseX::CachingProxy
For more information on module installation, please visit the detailed CPAN module installation guide.