How do I find a persistent DBIx :: Class in CGI :: Application with mod_perl?

I am using CGI :: Application on mod_perl with DBIx :: Class, and I would like something like new to define a new dbic schema when instantiating. So far, I have not been able to get it to work. The closest I came to is a superclass that has a connect () method that returns a new object, but I would prefer it to be already connected and created.

I would really appreciate any thoughts.

Thanks!

Note : Okay, so it obviously didn't help, but in the meantime I made an accessory that lazily creates an instance of DBIx :: Class, so that might be a little better. Check this:

sub schema { my $self = shift; unless ($self->{schema}) { $self->{schema} = ACD::Model->connect(@{$self->cfg->{$ENV{MODE}}->{connect_params}}); } return $self->{schema}; } 

and then of course use it, you would do something like:

 $self->schema->resultset('Foo')->find(1234); 
+4
source share
2 answers

Of course, you cannot serialize the database connection into a session file or anything else, and you cannot create it before the Apache forks, but you can save one alive to the child process.

The option to create one in advance is to do this in your base mod_perl module, but since the client connection has already begun at this point, it will not buy you any improvement in response time.

So, I would do a lazy implementation, just like you, but instead of caching the schema object in $self , cache it in a private variable of the package level, which will mean that each child apache process has exactly one schema connection: / p>

 my $_schema; sub schema { return $_schema if $_schema; # actually, you should check the db connection is live return $_schema = ACD::Model->connect(...); } 
+1
source

I don't have a single answer, but http://lists.scsys.co.uk/pipermail/dbix-class/2006-June/001690.html is probably worth reading, so you understand how DBIC manages connections.

0
source

All Articles