--- ProxyServer.pm.orig	Tue Nov 21 12:50:54 2000
+++ ProxyServer.pm	Tue Nov 21 13:17:22 2000
@@ -38,7 +38,7 @@
 
 use vars qw($VERSION @ISA);
 
-$VERSION = "0.2003";
+$VERSION = "0.2003-1";
 @ISA = qw(RPC::PlServer DBI);
 
 
@@ -97,6 +97,7 @@
     }
     $o->{'pidfile'}    = '/tmp/dbiproxy.pid';
     $o->{'user'}       = undef;
+    $o->{'connect_cached'}     = undef;     # When set, use connect_cached instead of connect
 };
 
 
@@ -168,7 +169,7 @@
 #            $password - Password
 #
 ############################################################################
-
+ 
 sub AcceptUser {
     my $self = shift; my $user = shift; my $password = shift;
     return 0 if (!$self->SUPER::AcceptUser($user, $password));
@@ -176,9 +177,16 @@
     $self->Debug("Connecting to $dsn as $user");
     local $ENV{DBI_AUTOPROXY} = ''; # :-)
     $self->{'dbh'} = eval {
-	DBI::ProxyServer->connect($dsn, $user, $password,
-				  { 'PrintError' => 0, 'Warn' => 0,
-				    RaiseError => 1 })
+        if ($self->{'connect_cached'}) {
+	    DBI::ProxyServer->connect_cached($dsn, $user, $password,
+				      { 'PrintError' => 0, 'Warn' => 0,
+				        RaiseError => 1 })
+        }
+        else {
+	    DBI::ProxyServer->connect($dsn, $user, $password,
+				      { 'PrintError' => 0, 'Warn' => 0,
+				        RaiseError => 1 })
+        } ;
     };
     if ($@) {
 	$self->Error("Error while connecting to $dsn as $user: $@");
@@ -236,6 +244,10 @@
 sub prepare {
     my($dbh, $statement, $attr, $params) = @_;
     my $server = $dbh->{'private_server'};
+
+    # If called localy (e.g. ping from connect_cached) simply call SUPER::prepare
+    return $dbh->SUPER::prepare($statement, $attr) if (!$server) ;
+
     if (my $client = $server->{'client'}) {
 	if ($client->{'sql'}) {
 	    if ($statement =~ /^\s*\S+/) {
@@ -554,6 +566,20 @@
     $sth->prepare("insert");
 
 which in fact are "SELECT * FROM foo" or "INSERT INTO foo VALUES (?, ?, ?)".
+
+
+=head2 Cacheing Connections
+
+To minimize the overhead of connecting to the database server, you may set the
+option 'connect_cached' in the config file, in which case DBI::ProxyServer uses
+the DBI connect_cached method to setup a new connection, so if a matching
+connection already exists, it is reused by DBI::ProxyServer. 
+
+B<NOTE:> This does not work in B<fork mode>, because the child will terminate 
+after the you disconnected and therefore the connection to the database will
+be closed and cannot be cached, but using it together with B<pre-fork mode>,
+by setting the 'childs' configuration directive of Net::Daemon, works pretty well.
+
 
 
 
