Caching a model?


I am using memcahced_client for caching. I also have cached_model
installed as a gem install. I have a user object that in turn has a
hasmany relationship to a reviews model.

So, once user logs in, i have soemthing like

@reviews =

and reviews has been defined as follows in the user_profile model


has_many :reviews, :class_name => “UserReviews”, :foreign_key
=> :user_id, :limit => 1000, :order => :review_date

I then try to cache the @reviews using

Cache.put key,@reviews.

Next i try to retreive it using

Cache.get key

Here is my code for that.
@reviews = Cache.get @user_profile.user_id.to_s+’_reviews’
@reviews = nil
if @reviews == nil
@reviews =
Cache.put @user_profile.user_id.to_s+’_reviews’, @reviews

Neither the put nor the get seem to be working. I think it has
something to do with the marshalling. Can anyone help?

Thanks in advance

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs