Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

caching with memcached

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>
like image 912
badnaam Avatar asked Feb 11 '26 22:02

badnaam


1 Answers

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.

like image 165
Jesse Wolgamott Avatar answered Feb 14 '26 11:02

Jesse Wolgamott