开发者

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>&开发者_运维知识库lt;%= link_to current_user.username.titleize, current_user, :id => 'main_profile_link' %></li>
                  <li><%= link_to "Logout", logout_path  %></li>
                <% end %>
              </ul>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜