caa*_*os0 6 caching ruby-on-rails
我有这样的事情:
class Suite < ActiveRecord::Base
has_many :tests
end
class Test < ActiveRecord::Base
belongs_to :suite
end
Run Code Online (Sandbox Code Playgroud)
我正在使用cache_digests gem来进行片段缓存.我希望在更新Suite对象时,子测试缓存过期.我试图touch: true在has_many协会中没有成功.
我怎样才能做到这一点?
提前致谢
我这样做我的缓存:
<% cache test do %>
<tr>
etc...
<% cache test.suite do %>
etc..
<% end %>
</tr>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为当我编辑套件时,他们的测试没有被触及.所以,我将缓存声明更改为:
<% cache [test, test.suite] do %>
etc..
<% end %>
Run Code Online (Sandbox Code Playgroud)
它的工作方式与预期一致.
当我编辑测试或套件时,其中一个被触及,因此,片段已过期,我按预期获得了新版本.
感谢@ taryn-east的帮助.
此页面: https: //github.com/rails/rails/issues/8759
建议使用 after_save 挂钩:
class Post < ActiveRecord::Base
has_many :assets
after_save -> { self.touch }
end
class Asset < ActiveRecord::Base
belongs_to :post
end
Run Code Online (Sandbox Code Playgroud)