NAME

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

DESCRIPTION

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.

WARNING

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.

SYNOPSIS

  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 = (
	'http://www.example.com/robots.txt',
	'http://example.com/robots.txt',
  );

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

	print $res->content;
  }

CONSTRUCTOR PARAMETERS

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

resolver

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).

do_res_cache

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.

SEE ALSO

For actual connection cacheing functionality see LWP::ConnCache

AUTHOR

Sergey Chernyshev, <sergeyche@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Sergey Chernyshev <sergeyche@cpan.org>

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.