[Dbix-class] Caching connections

Jesper Krogh jesper at krogh.cc
Sun Apr 30 22:12:46 CEST 2006


Dan Horne wrote:
> According to the docs
> 
> "Note that DBIx::Class::Schema does not cache connections for you. If you
> use multiple connections, you need to do this manually."
> 
> As I'm using DBIx::Class under FastCGI, I'd like to cache my connection with
> DBI's connect_cached connection method. Is there a way that I can do this?

I a setup I'm working on.. I have code that automatically shifts the
user based on the logged in user in Catalyst (that comes from mod_ntlm
in Apache). It basically stores the old schema in a hash:

$cache->{$username} ||= DB->connect("dbi:Pg:...... ");

And then uses that schema for all further processing.

It "unfortunately" does not share the cache between different
FastCGI-processes since each process has thier own memory-space and so
forth. This makes it impossible to have a transaction over several
http-request, but I think that stuff like that would be to hairy for me
anyway. But it enables me to reflect the authenticated user directly
into the database.

Then I have the database to automatically update created_user and
modified_user, on all records in the database, which gives a nice way of
tracking "who did what when".

Jesper
-- 
Jesper Krogh, jesper at krogh.cc




More information about the Dbix-class mailing list