Hateburo: kazeburo hatenablog

Operations Engineer / Site Reliability / 運用系小姑 / Perl Monger

How to keepalive more than one connections with Furl - Furlで2個以上の接続を維持する技

Furl can do keepalive connection by passing connection pool object to connection_pool option, By default, Furl::ConnectionCache is used.
But Furl::ConnectionCache can keep only one connection at once.

To do keepalive more one connections. you need to make a connection pool object like this example.

my $conncache = Cache::LRU->new(size => 10);
my $furl = Furl->new(
    connection_pool => Plack::Util::inline_object(
        steal => sub{ my $key = $_[0].':'.$_[1]; $conncache->get($key) },
        push => sub{ my $key = $_[0].':'.$_[1]; $conncache->set($key,$_[2])  }



Why Plack::Util? Plack will be installed anywhere