【发布时间】:2013-02-23 00:04:12
【问题描述】:
以下是我的观点:
学生/show.json.rabl
object @student
cache @student
attribute :name, :gender, :age
node :school do |student|
partial("shared/school", :object => student.school)
end
shared/_school.json.rabl
object @school
cache @school
attributes :id, :name
student.rb:
class Student < ActiveRecord::Base
belongs_to :school, :touch => true
end
school.rb
class School < ActiveRecord::Base
has_many :students
end
因此,当我更新学生时,缓存会按预期失效。问题是当我更新学校时,学生没有得到更新的学校属性。当我更新学校模型时,我原以为部分中的缓存 @school 会失效,但事实并非如此。
编辑:添加了对学生的触摸以在更新时使学校无效。
【问题讨论】:
标签: ruby-on-rails caching ruby-on-rails-3.1 rabl