[Dbix-class] Caching a resultset?

Alexander Hartmaier alexander.hartmaier at t-systems.at
Mon Jan 14 08:26:04 GMT 2013


On 2013-01-14 05:35, Jesse Sheidlower wrote:
> I have a Catalyst app that very frequently (pretty much every request)
> requires several DBIC resultsets that return a small number of values,
> that very rarely change. I'm trying to cache this, so I can update the
> cache when the values change and not have to hit my DB a half-dozen
> times on every request for data that is effectively static.
>
> Originally the relevant line was along the lines of:
>
>   $c->stash->{subjects} = $c->model('WordsDB::Subject')->search();
>
> I replaced this, following the C::P::Cache docs, with
>
>   unless ( $c->stash->{subjects} = $cache->get( 'subjects' ) ) {
>     $c->stash->{subjects} =
>         $c->model('WordsDB::Subject')->search();
>     $cache->set( 'subject', $c->stash->{subjects} );
>   }
>
> However, this dies (on a second run, when it's actually hitting the
> cache) with "undef error - Can't call method "select" on an undefined
> value at /usr/share/perl5/DBIx/Class/ResultSet.pm line 957". So I'm
> assuming that I can't just stuff a RS into the cache and expect it to
> work. Is there an easy way around it? (I know I could retrieve the
> actual data and put that into the cache, but then I'd have to rewrite a
> whole bunch of templates, that are expecting a resultset.)
>
> Thanks.
>
> Jesse Sheidlower
>
> _______________________________________________
> 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/dbix-class@lists.scsys.co.uk
The resultset has a ref to the schema which in turn has one to its
database connection which can't be serialized/cached.
After unfreezing it you have to link the $rs back to a schema with a
working database connection.
I wasn't able to find this in the docs although I'm pretty sure I've
read it sometimes.

--
Cheers, Alex


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list