[Catalyst] Multiple DB, single instance of Cat

Matt S Trout dbix-class at trout.me.uk
Wed Sep 24 16:04:30 BST 2008

On Thu, Sep 11, 2008 at 11:58:31PM +0100, Nigel Stuckey wrote:
> Matt
> I stand corrected on DBIx! Yes, indeed I mean DBIx::Class.
> The code is in and works, but has a couple of issues. Firstly, it  
> creates new classes and carries out a DB connect every time there is  
> a request. Is there a way to make it more efficient by caching the  
> classes and DB connects once there is a successful authentication?

It should only be creating a new $schema object, see below.

No reasony you can't do


and then set that to {} somewhere early and keep the $schema objects in

I didn't do this in my example because (1) IT WAS A SIMPLE EXAMPLE (2)
writing caching code is simple, except you need to handle cache expiry
and stuff and I didn't have time to write example code for all of that :)
> Secondly, there are loads of 'ACCEPT_CONTEXT redefined' messages, one  
> per DB table defined to the DBIC model. When initialising, I have to  
> give the 'dynamic' model an initial configuration to allow Catalyst o  
> start.

Ah, the class creation and stuff shouldn't be happening. That's me being
silly, what you want to do is

my $new = bless({ %$self }, ref($self));

to bypass the initialisation phase.

> Once the code is working I will pop it on the wiki.

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list