Rails.cache.fetch with additional values ​​added

We have a page that shows the top groups for our application. Leaderboard pricing is expensive, so we cache the results for an hour as follows:

@groupboard = Rails.cache.fetch("top_groups", :expires_in => 1.hour) do Group.top_groups end 

This gives an error after the cache was written for the first time. While in the console, I see that Group.top_groups returns an array of elements that look like this:

 [#<Group id: 4, name: "IBP", rank: 6, users_count: 13, leader_id: 4662>, 3887] 

When I look at the result returned from the cache, it looks like this:

 [#<Group id: 4, name: "IBP", rank: 6, users_count: 13, leader_id: 4662>, :@new_record_before_save], false, 3887] 

Does anyone know what @new_record_before_save will call and the value "false", which will be inserted into all entries for this object in the cache?

We use Dalli, Memcached 1.4.9, Rails 3.2.4, Ruby 1.9.2

+4
source share
1 answer

There is a Rails cache error in an AR object that has an associated object. Try the following:

 @groupboard = Rails.cache.fetch("top_groups", :expires_in => 1.hour) do Group.top_groups.map(&:reload) end 

see more at https://github.com/mperham/dalli/issues/250

+2
source

All Articles