ruby-on-railsmemcacheddallifragment-caching

Rails: Trying to understand how to do better fragment caching


In my app I am trying to incorporate better fragment caching.

Is it a best practice to do call fragments like this:

<% cache("user/#{current_user.id}/info") do %>
  <%= current_user.email %> information goes here
<% end %>

Solution

  • Yes you are doing it right!

    Why? The cache fragment's key must reflect the "uniqueness" of the content: