LWP::ConnCache::Resolving - resolving connection cache.


LWP::ConnCache::Resolving can be used to add resolution to LWP::ConnCache.

It might be useful if you have multiple hostnames that result in the same logical connection which can be interchangably used for all of them (either have the same IP address or connect to the same farm of load balanced servers, for example).

Module itself does not define a resolution mechanism leaving it to the user to define (I'll probably write DNS resolver as pre-canned module in the future) - see resolver constructor parameter.


Be careful with HTTP load balancers which sometimes use Host header to keep connection to different backend servers - this connection might not be reusable for request with different Host headers even if hostname resolves to the same IP address.


  use LWP::UserAgent;
  use LWP::ConnCache::Resolving;

  my $ua = new LWP::UserAgent(
        conn_cache => new LWP::ConnCache::Resolving(
                total_capacity => 20,
                do_res_cache => 1,
                resolver => sub {
                        # LWP::Protocol::http uses "host:port" pair as a key
                        my $key = shift;
                        return "www.$key" unless $key =~ /^www\./i;
                        return $key; # otherwise return what we got

  my @urls = (

  foreach my $url (@urls)
        my $res = $ua->get($url);

        print $res->content;


To configure resolution, you can pass some parameters to object constructor (see. SYNOPSYS section above)


This parameter accepts a subroutine that gets LWP::ConnCache cache key as single parameter and must return a resolved version that will be used instead of original one.

If this subroutine returns false value, it'll be ignored and original key will be used.

This parameter is mandatory (otherwise you can simply use regular LWP::ConnCache instead).


This attribute allows you to enable resolution cache. This is true (enabled) by default. If your resolution is not deterministic (changes from call to call), then it makes sense to disable it by setting do_res_cache to false.


For actual connection cacheing functionality see LWP::ConnCache


Sergey Chernyshev, <>


Copyright (C) 2007 by Sergey Chernyshev <>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.