Last week I released MooseX::CachingProxy to CPAN.

Its a small module that intercepts requests from your LWP based application. Those requests are relayed on to the intended server unless they already exist in the cache.

To toggle on and off the caching proxy, MooseX::CachingProxy provides the attribute ‘caching_proxy’. Here is a quick demo:

package MyApp;
use Moose;
use WWW::Mechanize; # or any LWP based library
with 'MooseX::CachingProxy';

sub url { '' } # required by MooseX::CachingProxy

sub download { 
    my $self = shift;
    return WWW::Mechanize->new()->get($self->url . '/foo'); 

Under the covers, its a tiny Plack application that mashes up Plack::Middleware::Cache and Plack::App::Proxy.