问题描述:

So I have these two lines:

@unTaggedPhotos = Photo.cached_unTagged.sort_by{rand}[0..7]

which calls:

Rails.cache.fetch('unTagged', :expires_in => 20.minutes) {Photo.where("hide = 0").limit(300)}

And the first time I load a page after clearing the cache it works, but then I get the frozen object error.

The weird thing is this does not seem to be a problem on the live version of my site running the same code. (I have other things cached that work on the local version too)

网友答案:

I'm not sure if this is the best way to handle the problem, but when I break it into two steps and call ruby's dup method when referencing the cached data it doesn't complain about being frozen anymore.

myUTP = Photo.cached_unTagged.dup
@unTaggedPhotos = myUTP.sort_by{rand}[0..7]
相关阅读:
Top