I have a fairly large Rails app, which uses memcached on a seperate server as its cache store.
The problem is that I randomly get errors in the production environment which seem to indicate that memcached is returning an incorrect object.
Examples:
In this example, current_site
is a helper method which accesses a method on the Site
model that uses Rails.cache to cache the model
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:
contrasted with....
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:
When both should be returning a Site
model!
Another example of cache behaving strangely:
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>
Has anyone encountered something like this before? Anyone have thoughts on diagnosing this unreplicable problem!? I've tried switching out memcached client gems, thinking maybe it was a weird bug, but this didn't have any effect! Thanks.