Name

connect_cached (NEW )

Synopsis

$dbh = DBI->connect_cached($data_source, $username, $password)
          || die $DBI::errstr;
$dbh = DBI->connect_cached($data_source, $username, $password, \%attr)
          || die $DBI::errstr;

connect_cached is like connect, except that the database handle returned is also stored in a hash associated with the given parameters. If another call is made to connect_cached with the same parameter values, then the corresponding cached $dbh will be returned if it is still valid. The cached database handle is replaced with a new connection if it has been disconnected or if the ping method fails.

Note that the behavior of this method differs in several respects from the behavior of persistent connections implemented by Apache::DBI.

Caching can be useful in some applications, but it can also cause problems and should be used with care. The exact behavior of this method is liable to change, so if you intend to use it in any production applications you should discuss your needs on the dbi-users mailing list.

The cache can be accessed (and cleared) via the CachedKids attribute.

Get Programming the Perl DBI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.