Hi,

Thanks for your response. I also saw your post here:
http://grokbase.com/post/2007/11/22/catalyst-dbic-v-cache-what-are-catalyst-best-practices-for-caching-dbic-results-with-relationships-included/vXQc8SjXITu1G9Lf4RD_-ZJLTZQ

which gave some insight and at the same time raised some questions in my head. 
First, I realized that there was a mistake in my code, the current one that is 
working looks like this

..
..
    if ( $data = $c->cache->get($cache_key) ) 
    {        
$data->result_source($c->master->schema()->source('table_schema_name'));
    }
    else
    {
      $data =
        $c->master->resultset('table_schema_name')->search( 
          \%search_condition,
          {
            prefetch => 'table_relations',
          }
        );
      $c->cache->set( $cache_key, $data );
    }
    $data = $data->first;
..
 ..
 
And reading Matt S Trout's posts there, I suppose that there are actually two 
types of caching:
- per query cache (database)
- object construction cache 

And I also assume that the object is constructed by using methods like "search" 
and the query is performed by using methods such as "first", like what 
Hartmaier had said, and thus, the caching that I am trying to implement now is 
the object construction caching. Please correct me if I am wrong
 here.

Then, I tried to test if this caching can actually make the response time 
faster by using Benchmark::Timer, but I was surprised to find out that most of 
the time, performing "search" is a little bit faster than getting the value 
from the cache.

Actually, I think that the bottleneck in my case here is the time it takes to 
perform database queries. I haven't tried DBIx::Class::Cursor::Cached yet, but 
looking at the posts, it seems more appropriate for me than  Cache::Memcached. 
Any thought how long a value will stay (valid) inside the
 cache in DBIx::Class::Cursor::Cached ?

Sindharta


Tobias Kremer <[EMAIL PROTECTED]> wrote: >  Couldn't render template "undef 
error - Can't call method "source" on an
> undefined value at
> /usr/lib/perl5/site_perl/5.8/DBIx/Class/ResultSourceHandle.pm line 64.

You lost your ResultSource. This is normal when storing ResultSets in a cache
AFAIK. Use DBIx::Class::Cursor::Cached (works great) or reset th
ResultSource after fetching your data from the cache. If my memory serves you
can do that like this:

my $rs = $c->cache->get( 'cachekey' );
...
$rs->result_source( $c->model( 'MyModel' )->source( 'result_source_classname' )
);

Maybe there is an even simpler way ...

HTH

--Tobias

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

 

 
---------------------------------
Easy + Joy + Powerful = Yahoo! Bookmarks x Toolbar
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to