On Wed, 24 Jan 2007, Jim Spath wrote:

Ash Berlin wrote:
 Jim Spath wrote:
> I was wondering if anyone had any suggestions for how to properly use > memcached (http://www.danga.com/memcached/) with DBIx::Class. > > When one tries to store a resultset in memcached, you get the error > "Can't store CODE items", which makes sense. > > It seems like I really only have one choice, which is to create a > string/arrayref/hashref of the data returned from the resultset before > storing it in memcached and using it in my code. But that feels a > little ugly to me. > > Any ideas? > > - Jim > > PS - I'm running running both DBIx::Class and Cache::Memcached under > Catalyst, if it matters.

 IIRC the CODE segment it is refereeing to is in fact the dbh deep down in
 storage.

 In the -current branch (which is due for release soon) we completely
 refactored how objects and result sets keep hold of their ResultSource's.
 Instead of storing a direct reference to a ResultSource, they now store a
 tuple of (source_name,schema)

 This has the added benefit that you can store only the source_name when
 you put an RS into memcached, and re-attach it to the schema when you read
 it out.

 
<http://dev.catalyst.perl.org/trac/bast/browser/branches/DBIx-Class-current/lib/DBIx/Class/ResultSourceHandle.pm>

 The above file has freeze and thaw hooks for Storable, but bear in mind
 that the schema is not automatically reattached (couldn't work out a good
 way of doing it) so you'd have to come up with a way of expressing it or
 just do something hacky like:

 $newly_thawed_obj->_source_handle->schema($schema);

 But please don't do that, cos it will break horribly in all kinds of
 cases.

 </incoherent ramblings>

 Ash

Thanks Ash,

Sounds interesting.

I have actually had some success with running search() calls in list context and storing the returned array of row objects in memcached.

However, I am worried about the memory requirements of storing an array of objects in memcached when all I need is an array of hash references.

Is there and easy way to return just the data from DBIx::Class or am I stuck with having objects returned?

Like reading the docs? ;)

Either call ->get_columns on each of those objects or look at the hashrefinflator (see cookbook).

Jess


_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to