views:

55

answers:

1

I have a section in my main layout like the following. I am starting to use memcached and wondering if this portion can be cached somehow becasue the current_user call makes a hit to the database for every page load and by nature of the plugin (authlogic) thats behind it, it actually updates the user record (i.e. the perishable token).

Is there anyway around this through caching or any other means?

<ul class="header_links">
                <% unless  current_user %>
                  <li><%= link_to "Sign Up", new_user_path, :id => 'main_sign_up_link', :class=> 'special-text'%></li>
                  <li><%= link_to "Login", login_path, :id => 'main_login_link' %></li>
                <% else %>
                  <li><%= link_to "New Vote", new_user_vote_topic_path(current_user), :id => 'main_new_vote_link',  :class=> 'special-text' %></li>
                  <li><%= link_to current_user.username.titleize, current_user, :id => 'main_profile_link' %></li>
                  <li><%= link_to "Logout", logout_path  %></li>
                <% end %>
              </ul>
+1  A: 

Are you using the perishable token? This SO question says you can either remove that column, or set disable_perishable_token_maintenance = true to prevent the update-db hit per page load.

As for caching -- in general you can cache non-personalized data for everyone, and personalized data for only that person. So yes, you could cache that block, but the key would need to have the user_id in it.

Jesse Wolgamott
Thanks. It seems I do use pt for resets/account validations, is there a way I can use it only for those requests? or if I remove this column can I still have reset functionality some other way?
badnaam
Set the disable_perishable_token_maintenance = true and then reset it when you do resets and validations
Jesse Wolgamott