class CodeBlock < ApplicationRecord
belongs_to :snip, touch: true
end
<% cache(@snip) do %>
<h1><%= @snip.title %></h1>
<%= render @snip.code_blocks %>
<% end %>
When a child record changes, you often want the parent cache key to change too. touch: true is a clean primitive for that. It keeps fragment caching sane without complex dependency graphs.