[Catalyst] query once per session?

Michael Higgins mhiggins at banfieldgroup.com
Mon Apr 30 17:20:45 GMT 2007


> From: Yuval Kogman [mailto:nothingmuch at woobling.org] 
> 
> On Fri, Apr 27, 2007 at 10:32:15 -0700, Michael Higgins wrote:
> 
> > Ah. Well, I got something working, I believe, using 
> Cache::FileCache...
> > which is marginally faster than retreieving it every time. 
> Probably, I 
> > need a different cache method.
> 
> I recommend Cache::FastMmap. New versions of that module no 
> longer need the wrapped version I have on the CPAN 
> (Catalyst::Plugin::Cache::Backend::FastMmap or something like 
> that, don't use it ;-). I really need to upload one with a deprecation
> notice) so it should be a drop-in replacement. This is shared 
> by the various webserver child processes and is supposed to 
> be much more efficient than Cache::FileCache.

Okay, I'll look into that, perhaps. For now, the problem is 'fixed' well
enough.

> 
> Also make sure that you cache the most processed version of 
> the data structure that you can, and not a large object set 
> (you might be serializing the whole DBIC schema every time 
> you cache if you're not careful). If you're in doubt, use 
> Data::Dumper to see what the caching module will have to 
> serialize and deserialize each time.

I'm afraid this doesn't mean anything to me yet. I'm caching like this:

    unless ( $result = $cache->get( 'clients' ) ) {
        $result = [$c->model('BanTraceDB::TBGClient')->search(
                         {},{ order_by=>'name ASC'}
                          )];

        $c->cache->set( 'clients', $result );
        }

I don't know what's happening 'under the hood'.

> You can load the DBIx::Class::Serialize::Storable component 
> if you want to serialize row objects. Note that serializing 
> resultsets is probably meaningless since resultsets.

Do I want to serialize? Is it returned that way already?

> 
> > It seems the most expensive part might be moving the data 
> to the client.
> > Maybe I could I speed that up somehow? 
> 
> look into mod_deflate if your server is apache, or similar 
> solutions. I think there is even a Catalyst plugin to do that.

Right.

> 
> > Or, I think you mentioned just coding it into a javascript 
> and having 
> > that load into the page when requested. I like this idea. This data 
> > can persist for a while. I could have a link to explicitly 
> refresh the 
> > list, no? This is for internal use, basically. Clients have this 
> > number hard-coded in their session.
> 
> If you make a catalyst URI that pretends to be a static, 
> cachable file then you can attach a Last-Modified header, and 
> respect the client's If-Modified-Since header, giving a not 
> modified response instead of the page content.
> 
> See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25


So, what I did is to use Plugin::PageCache. Now, the page is returned
client-side after the first reqeust. Good enough for now. ;-)

[8<]

Thanks for all your suggestions!

--
   .     .   .   .   .  ....    .   .   .     ..     ..    .   .   .  .``.
   .`. .`.   .   . .`   .       .   .   .   .`     .`      .   .`. .  `.
   .  `  .   .   .`.    .``     .```.   .   .  ..  .  ..   .   .  `.    `.
   .     .   .   .  `.  ....    .   .   .    `..`   `..`   .   .   .  `..`
 





More information about the Catalyst mailing list