[![Build Status](https://travis-ci.org/kablamo/MooseX-CachingProxy.svg?branch=master)](https://travis-ci.org/kablamo/MooseX-CachingProxy) [![Coverage Status](https://img.shields.io/coveralls/kablamo/MooseX-CachingProxy/master.svg)](https://coveralls.io/r/kablamo/MooseX-CachingProxy?branch=master) # NAME MooseX::CachingProxy - Send LWP requests through a caching proxy server # SYNOPSIS 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; } # DESCRIPTION This is a Moose role that allows you to easily cache responses from remote servers. For this to work, use either [LWP](https://metacpan.org/pod/LWP) or a library that uses LWP (like [WWW::Mechanize](https://metacpan.org/pod/WWW::Mechanize)). The implementation is a mashup of [Plack::App::Proxy](https://metacpan.org/pod/Plack::App::Proxy), [Plack::Middleware::Cache](https://metacpan.org/pod/Plack::Middleware::Cache), and [LWP::Protocol::PSGI](https://metacpan.org/pod/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. ## Attributes ### url Required. All requests are proxied to this server. Example: http://example.com. ### caching\_proxy\_dir Optional. The directory on the local filesystem where responses are cached. The default location is '/tmp/caching-proxy'. ## Methods ### start\_caching\_proxy() Start intercepting LWP requests with a caching proxy server ### stop\_caching\_proxy() Start intercepting LWP requests with a caching proxy server # THANKS Thanks to Foxtons Ltd for providing the opportunity to write and release the original version of this module. # SEE ALSO [Plack::App::Proxy](https://metacpan.org/pod/Plack::App::Proxy), [Plack::Middleware::Cache](https://metacpan.org/pod/Plack::Middleware::Cache), [LWP::Protocol::PSGI](https://metacpan.org/pod/LWP::Protocol::PSGI) # AUTHOR Eric Johnson # COPYRIGHT AND LICENSE 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.