我有两个模型 - 发布和评论。我使用片段缓存来缓存每个post
像这样:
- @posts.each do |post|
- cache post do
= render 'posts/post', post: post
post.rb
class Post < ActiveRecord::Base
belongs_to :user, touch: true
has_many :comments, dependent: :destroy
end
现在我的comments.rb
文件如下:
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :post, touch: true
end
这按预期工作。每当我向帖子添加新评论时,该特定帖子的缓存键都会过期。但是,当我从帖子中删除评论时,该帖子的缓存键不会过期。是什么赋予了?