Zitat von Perrin Harkins <[EMAIL PROTECTED]>:

> You need to separate managing your database connections from caching
> this data.  They are not related, and there's no reason to do both in
> one class.  Either just call connect_cached all the time (it uses
> Apache::DBI when it finds it loaded), or make your own database
> connection singleton that decides how to connect in the current
> environment.  Keep your data in the object as you planned.

Ok, got that! But how does the class get its database handle to operate on?
I have already put the database connection stuff into a separate class
(let's call it My::Database). My::Database has a constructor
which connects to the database, stores the handle in $self->{_dbh} and a
method "dbh" which returns this handle. Now My::Structure does the following:

sub new {
  ... $self->{_dbh} = My::Database->new()->dbh(); ...
}

sub init {
  ... prepare data using $self->{_dbh} and store it ...
}

sub query_something_during_request {
  ... again using $self->{_dbh}  ...
  # this is where a "stale", non-cached database handle will get used, right?
}

One solution that just popped into my mind is changing My::Database's "dbh"
method so that it always connects using connect_cached instead of doing it
once during creation of My::Database. Would that be a feasible solution?

Again thanx a lot!

Toby

Reply via email to