rails 4缓存过期无效

在我的rails应用程序中,我正在尝试使用嵌套缓存,但是当user.profile.full_name更改时,我的缓存键未到期。 因此,当用户更改他/她的名字时, _profile_product.html.erb显示的full_name仍然是旧名称。

我该如何更换钥匙?

型材/ show.html.erb

  #this is the profile info and the cache key expires properly when @profile.full_name changes  .....   #not nested in the previous cache; #products belonging to the profile are listed with this code under the profile info   

_profile_products.html.erb

    

_profile_product.html.erb

    #if I change profile name this one won't change thanks to the cache  

尝试更改缓存键

_profile_products.html.erb

 <% cache(['profile-products', @profile_products.map(&:id), @profile_products.map(&:updated_at).max, @profile_products.map{|pp| pp.user.profile.updated_at.to_i }.max]) do %> <%= render partial: "products/profile_product", collection: @profile_products, as: :product %> <% end %> 

问题是当用户更新其配置文件名称时,包含整个列表的cachefragment不会过期。

通过将关联的用户配置文件的updated_at的最大值添加到缓存键,缓存片段将在用户更新其配置文件时到期。