I have such action in my controller: def my @user = Ads::User.find current_user.id @postings = Rails.cache.fetch("@user.postings.includes(:category)") do @postings = @user.postings.includes(:category) end end I''m trying to cache @postings and get such error: Marshalling error for key ''@user.postings.includes(:category)'': can''t dump anonymous class #<Module:0x000000048f9040> You are trying to cache a Ruby object which cannot be serialized to memcached. If I try to cache @postings without includes there are no errors. Can''t figure out what is the problem -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/2lARlH6VlEkJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-25 12:19 UTC
Re: rails memcached dalli Marshalling error for key
On Dec 25, 11:09 am, Pavlo Shabat <pavlo.sha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have such action in my controller: > > def my > > @user = Ads::User.find current_user.id > > @postings = Rails.cache.fetch("@user.postings.includes(:category)") do > > @postings = @user.postings.includes(:category) > > end > > end > > I''m trying to cache @postings and get such error: >This would try and cache the activerecord::relation object rather the actual query results. You need to force execution of the query, ie Rails.cache.fetch("@user.postings.includes(:category)") do @user.postings.includes(:category).to_a end Fred> Marshalling error for key ''...@user.postings.includes(:category)'': can''t dump > anonymous class #<Module:0x000000048f9040> > > You are trying to cache a Ruby object which cannot be serialized to > memcached. > > If I try to cache @postings without includes there are no errors. Can''t > figure out what is the problem-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Tue, Dec 25, 2012 at 5:09 AM, Pavlo Shabat <pavlo.shabat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You are trying to cache a Ruby object which cannot be serialized to > memcached.What is "includes" and what does it return? It should be a String, Hash ({}), Array ([]), Fixnum (1), Range (1..2) or Float (1.0) for Dalli to not bitch about Marshaling. Otherwise you have to build your own Marshals for the object which might or might not be worth it. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
includes performs a join, and returns a ActiveRecord::Relation object. Just call .to_a like Frederick Cheung says, and Dalli will be happy :) -- Dheeraj Kumar On Tuesday 25 December 2012 at 9:50 PM, Jordon Bedwell wrote:> On Tue, Dec 25, 2012 at 5:09 AM, Pavlo Shabat <pavlo.shabat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org (mailto:pavlo.shabat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org)> wrote: > > You are trying to cache a Ruby object which cannot be serialized to > > memcached. > > > > > What is "includes" and what does it return? It should be a String, > Hash ({}), Array ([]), Fixnum (1), Range (1..2) or Float (1.0) for > Dalli to not bitch about Marshaling. Otherwise you have to build your > own Marshals for the object which might or might not be worth it. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.