[Catalyst] Singleton or Memcache

Matt S Trout dbix-class at trout.me.uk
Tue Oct 17 13:00:11 CEST 2006


Matthias Ludwig wrote:
>> Don't use a singleton. Instead, devise a Catalyst::Model api for
>> your tree structure, so that you can do:
>>
>> 	$c->model("MyTree")->get_that_node($which);
>> 	$c->model("MyTree")->get_the_root_node;
>>
>> or whatever.
> 
> makes sense :)
> 
>> You should probably pre-load this structure at setup time to get it
>> to be shared between all the child processes, but if it grows too
>> big to be pre-loaded you can have the tree lazily load itself using
>> a cascade of caches.
> 
> Ok, good idea! next problem ;)
> Is it possible to reach DBIx::Class-models while loading my own module?
> 
> In my controllers i can use objects in the database-table like this:
> $c->model('MyAppDB::XXX') but i don't have access to the context while
> preloading my tree?!

You don't need it, that's an app-level method pretty much. You get passed the 
$app (currently the string "MyApp", don't rely on that.) at model 
instantiation time, and you can hang on to it for that sort of purpose with 
our blessing :)

If you want an example of this, have a look at how Catalyst::Base hangs onto 
it for the purposes of $controller->action_for ...

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list