perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Kremer...@funkreich.de>
Subject (Database-)Object initialization during server-startup
Date Fri, 23 Jun 2006 12:47:03 GMT
Hey guys,

I'm wondering what's the best way to design a database-backed module
which works completely on its own as well as within mod_perl (mp1).
The module should make a database connection during object initialization
(new). This connection should then be used by all methods which want to
access the database (because I don't want to call "connect" before every
database query). That's easy under standalone conditions (connect within new,
store the dbh in $self->{_dbh} and use that in other methods).

Enter mod_perl. I'd like to create the object only ONCE during
server startup because it has to do some fairly heavy processing
with data from the database which I don't want to be done on every
request. The resulting state (some data structures) should then be saved
within the object's attributes for later quick and easy retrieval during
the request phase. Furthermore this object has methods which execute
more database queries (using the handle stored in $self->{_dbh}).

Now here's my concern: Because Apache::DBI will not cache the database
handle that was created during startup (some mechanisms luckily prevents
this), I fear that I might run into trouble having requests using the
object generated at server startup with a non-cached handle inside that is
shared among all apache children. I know that one should connect
in the request phase and let Apache::DBI do the magic, but in this case,
where the module is designed to be also used standalone, this is quite
tricky IMHO.

Hope you get the problem! Any ideas?

Thanx a lot!

Toby

Mime
View raw message