I am using fragment caching in rails 7 and encountering a issue . for reference, here is my view code which is views/users/index.html.erb
<p style="color: green"><%= notice %></p>
<h1>Users</h1>
<% cache "users_filter" do %>
<%= render partial: "users/partials/filter"%>
<% end %>
<table class="">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<div id="users">
<% @users.each do |user| %>
<% cache user do %>
<%= render user %>
<% end %>
<% end %>
</div>
</tbody>
</table>
<% cache "links" do %>
<%= link_to "New user from here", new_user_path %>
<%= link_to "Sign Out", destroy_member_session_path, data: { turbo_method: :delete} %>
<% end %>
Now my question is when I am changing anything in the links block which is at the end of this page, all the other cache blocks (which are already cached and does not change) also gets re-cached which they should not. I have separate cache keys for all of them but dont know why this is happening. For reference here are logs.
Started GET "/users" for ::1 at 2023-05-14 14:45:10 +0500
Processing by UsersController#index as HTML
Member Load (0.1ms) SELECT "members".* FROM "members" WHERE "members"."id" = ? ORDER BY "members"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Rendering layout layouts/application.html.erb
Rendering users/index.html.erb within layouts/application
Read fragment views/users/index:fd9e89346f2ad4b3c1b5b5e174f6150c/users_filter (0.1ms)
Rendered users/partials/_filter.html.erb (Duration: 0.4ms | Allocations: 281)
Write fragment views/users/index:fd9e89346f2ad4b3c1b5b5e174f6150c/users_filter (0.0ms)
User Load (0.1ms) SELECT "users".* FROM "users"
↳ app/views/users/index.html.erb:20
Read fragment views/users/index:fd9e89346f2ad4b3c1b5b5e174f6150c/users/17-20230514092800723809 (0.1ms)
Rendered users/_user.html.erb (Duration: 0.5ms | Allocations: 274)
Write fragment views/users/index:fd9e89346f2ad4b3c1b5b5e174f6150c/users/17-20230514092800723809 (0.1ms)
Read fragment views/users/index:fd9e89346f2ad4b3c1b5b5e174f6150c/links (0.0ms)
Write fragment views/users/index:fd9e89346f2ad4b3c1b5b5e174f6150c/links (0.0ms)
Rendered users/index.html.erb within layouts/application (Duration: 4.8ms | Allocations: 3024)
Rendered layout layouts/application.html.erb (Duration: 6.6ms | Allocations: 5589)
Completed 200 OK in 14ms (Views: 8.6ms | ActiveRecord: 0.2ms | Allocations: 7741)