I have a rails 4 app. I have to differentiate the different cache keys somehow but don't know the naming conventions.
FIRST EXAMPLE:
I have a task model with index
, completed_tasks
and incoming_tasks
actions. A have the same instance name (@tasks
) though because of the pagination.
At the moment the cache-keys are named like below. My questions: 1. Is the cache-key structure good enough? 2. Is it important in which order I put the parts of the key in the array? For example [@tasks.map(&:id), @tasks.map(&:updated_at).max, 'completed-tasks']
is better than ['completed-tasks', @tasks.map(&:id), @tasks.map(&:updated_at).max]
?
completed_tasks.html.erb
<% cache([@tasks.map(&:id), @tasks.map(&:updated_at).max, 'completed-tasks']) do %>
<%= render @tasks %>
<% end %>
tasks.html.erb
<% cache([@tasks.map(&:id), @tasks.map(&:updated_at).max]) do %>
<%= render @tasks %>
<% end %>
incoming_tasks.html.erb
<% cache([@tasks.map(&:id), @tasks.map(&:updated_at).max, 'incoming-tasks']) do %>
<%= render @tasks %>
<% end %>
SECOND EXAMPLE:
I also have problem with the naming conventions of the russian-doll-caching
:
products/index.html.erb
<% cache([@products.map(&:id), @products.map(&:updated_at).max]) do %>
<%= render @products %>
<% end %>
_product.html.erb
<% cache(product) do %>
<%= product.name %>
....
<% end %>
Is this version good enough or I always should put some string in both the outer and inner caching key array to avoid problems with similarly named cache-keys on other pages. For instance I plan to put <% cache(@product) do %>
on the profile#show
page which would be exactly the same like the inner caching in my example. If the key has to be different what the rails convention is to name the inner an outer cache keys?