[Dbix-class] memcached

Matt S Trout dbix-class at trout.me.uk
Thu Jan 25 08:56:35 GMT 2007


On 24 Jan 2007, at 22:10, 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?

The HashRefInflator code in svn will handle that.

-- 
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +





More information about the Dbix-class mailing list