[Dbix-class] Caching connections
Dan Horne
dan.horne at redbone.co.nz
Mon May 1 20:54:04 CEST 2006
From: Brandon Black
>
> If I'm understanding the scenario correctly, another option
> would be two persist two $schema objects based on the same
> Schema class, one for each connection. As in:
>
> sub fastcgi_proc_startup_handler {
> $persistent_stuff->{ro_schema} =
> My::Schema->connect('dbi:Pg:dbname=ro_db');
> $persistent_stuff->{rw_schema} =
> My::Schema->connect('dbi:Pg:dbname=rw_db');
> }
>
> And then based on your per-user logic at each request, do:
>
> sub handle_request {
> my $schema = $priveleged_user ?
> $persistent_stuff->{rw_schema} : $persistent_stuff->{ro_schema};
>
> my $foo = $schema->resultset(...)->....
> ...
> }
>
> The schema objects themselves will hold open cached
> connections correctly and all that, so you'll end up with up
> to one persistent connection per fastcgi process to each
> database (they won't actually connect until utilized, unless
> you're using Loader, which connects at load time).
>
Ok, I think most of my questions arose because I'm trying to use DBIx::Class
to fit the way I've done things in the past rather than understand its own
idiom. I get the caching of the schema now
Thanks to all who replied
Dan
More information about the Dbix-class
mailing list