[Catalyst] Singleton or Memcache

Wade.Stuart at fallon.com Wade.Stuart at fallon.com
Tue Oct 17 19:46:56 CEST 2006







catalyst-bounces at lists.rawmode.org wrote on 10/17/2006 03:53:12 AM:

> 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.
>
> 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.
>
> Using Cache::Cascade you can keep a small (several tens or hundreds
> of objects) cached per child process, and a memcached for another N
> mb, and then the least popular nodes will be loaded from the DB, and
> stored in the cache only when they're actually used.
>
> Essentially, what I'm saying is that $n MB is too large a structure
> to be useful for one cache entry. Scale it down, and divide it into
> smaller chunks, and then cache those if at all.
>
> However, when $n is 10 and not 100 it should be enough to just
> preload it.
>
> See also Devel::Size to check how much the structure really costs.

I would go even one step more and suggest you look at what is making you
think you need to load the full tree in the first place. Many times dealing
with large trees I have gotten stuck in the assumption that I would need to
act on the full tree, when after investigating further I was almost always
able to refactor and act on limited subsets and optimize the tree for
better use.  Can you go into what this tree is to be used for and the
structure in a little more detail so we may provide other options (if they
exist).

danke,

Wade




More information about the Catalyst mailing list