I have a Rails app that uses STI to handle different types of Users, such as:
class Admin < User ... end
I want to use memcached, but I keep getting the dreaded "unknown class/module" error. I've tried pre-loading all of my ActiveRecord models to no avail. The first request works as normal, but the first pull from memcached errors out. I've followed these instructions to no avail either.
Is using memcached possible with single table inheritance?
Route chaining in Rails?
Deploy from Git using Capistrano without a hard reset?
Rails routing for namespaced resource deletion
When you call it from memcached the class definition isn't loaded, and then you get the error..
Order of scopes in ActiveRecord/Rails queries
The workaround I use is:.
Retrieving and Ordering Multiple Arrays From ActiveRecord Join table - Ruby on Rails
Admin #lazily load the class definition # do whatever that has cached Admins
Rails: Authorization with Authlogic
Rails Nested Route For Singular Resource
Can't get value params[:user] first request using mongrel_rails start?
Pre-loading the STI user classes at the top of this method worked..
Also, I've found that this is unnecessary if you add.
to your production.rb (or development.rb for testing), this seems to catch all the models for caching.
config.cache_classes = true