Ben*_*use 6 ruby memcached caching ruby-on-rails
我有一个相当大的Rails应用程序,它在单独的服务器上使用memcached作为其缓存存储.
问题是我在生产环境中随机出现错误,这似乎表明memcached返回了一个不正确的对象.
例子:
在此示例中,current_site是一个辅助方法,它访问Site模型上使用Rails.cache缓存模型的方法
ActionView::TemplateError in ListingsController#edit
undefined method `settings' for #<String:0xb565f8a0>
On line #12 of app/views/layouts/site.html.erb
9: <meta name="robots" content="noodp, all" />
10: <meta name="distribution" content="Global" />
11:
12: <% unless current_site.settings[:google_webmaster_verification_code].blank? %>
13: <meta name="verify-v1" content="<%= current_site.settings[:google_webmaster_verification_code] %>" />
14: <% end %>
15:
Run Code Online (Sandbox Code Playgroud)
与...形成对比
ActionView::TemplateError in ApplicationController#not_found
undefined method `settings' for #<Category:0xd5c6c34>
On line #12 of app/views/layouts/site.html.erb
9: <meta name="robots" content="noodp, all" />
10: <meta name="distribution" content="Global" />
11:
12: <% unless current_site.settings[:google_webmaster_verification_code].blank? %>
13: <meta name="verify-v1" content="<%= current_site.settings[:google_webmaster_verification_code] %>" />
14: <% end %>
15:
Run Code Online (Sandbox Code Playgroud)
当两者都应该返回一个Site模型!
另一个缓存行为的例子很奇怪:
ActionView::TemplateError in AccountsController#show
can't convert Category into String
On line #141 of app/views/layouts/site.html.erb
138: <li<%= class="first" if i == 0 %>><%= link_to top_level_category.title, top_level_category.path %></li><% end %>
139: </ul>
140: <% end %>
141: <% cache bottom_pages do %>
142: <ul><% Page.top_level.active.show_in_navigation.find(:all, :include => :slugs).each_with_index do |top_level_page, i| %>
143: <li<%= class="first" if i == 0 %>><%= link_to top_level_page.title, top_level_page.path %></li><% end %>
144: </ul>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这样的事情?任何人都有想法诊断这个无法解释的问题!?我已经尝试切换出memcached客户端宝石,想想也许这是一个奇怪的错误,但这没有任何影响!谢谢.
Ben*_*use 10
这是由Passenger共享其与Memcached服务器的连接引起的.查看http://www.modrails.com/documentation/Users%20guide.html#_example_1_memcached_connection_sharing_harmful.
修复只是改变乘客的Rails产生conservative.