문제

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 %>
도움이 되었습니까?

해결책

Yes you are doing it right!

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

  • Statement: Your content is uniq for each user

  • Conclusion: Your fragment's key must be different for each user

  • Usage: using the user's id is the best choice since every user id is uniq!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top