I'm having trouble getting Plugin::Cache to handle DBIC objects correctly. Past instruction, and recent refresher, from MST shows that you have to reset/revive the result source and this works for a single object but blows up for prefetch.

In this code

        my $article = $c->cache->get($id);
        if ( $article )
        {
$article->result_source($c->model("DB")->source ("article"));
        }
        else
        {
            $article = $c->model("DB::article")->find($id)
                or die "RC_404: no such article";
            $c->cache->set($id, $article);
        }

No problem. But I really want to save the related object trips to the DB too. So, since articles may have comments I want to prefetch them as they will be used beneath an article. But then they are missing their result_source and resetting it does not seem to work(?). The following code produces an error when reloaded after first being cached.

        my $article = $c->cache->get($id);
        if ( $article )
        {
$article->result_source($c->model("DB")->source ("article"));
            $_->result_source($c->model("DB")->source("comment"))
                for $article->comments();
        }
        else
        {
            $article = $c->model("DB::article")
                ->find($id,
                       { prefetch => [qw/comments/] }
                       )
                or die "RC_404: no such article";
            $c->cache->set($id, $article);
        }

Caught exception in MyApp::Controller::Article->article "Can't call method
+ "source" on an undefined value at
+ /Library/Perl/5.8.6/DBIx/Class/ResultSourceHandle.pm line
+ 62."

What am I doing wrong? Can this be handled at all (resetting result_sources gets ugly fast when you bring in the other involved objects like user and document lineage)? What is the best practice regarding caching DBIC results in Catalyst?


Thanks!
-Ashley


_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to