Can't models be cached in development env?

i’m caching constant models in memory, but if
i try something like

@user.type = Rails.cache.read ‘types/1’

i get:

“ActiveRecord::AssociationTypeMismatch - Type(#39040660)
expected, got Type(#29355550)”

the class is the same, but the ids aren’t, so rails
refuse the association. but if i enable class_cache,
like in production, everything goes well. so here
is the question: is there a way to work with this
kind of caching in development mode? thanks.

ps: there is a thread with a similar problem
at ‘AssociationTypeMismatch: RoleType expected, got RoleType - Rails - Ruby-Forum’ but
their solution is not working for this rails
version.

On Jun 24, 4:22 am, Pepe J. [email protected]
wrote:

the class is the same, but the ids aren’t, so rails
refuse the association. but if i enable class_cache,
like in production, everything goes well. so here
is the question: is there a way to work with this
kind of caching in development mode? thanks.

Not really. The problem is that after each request rails tears down
the classes it has loaded and guts them (and then unsets the
corresponding constant), so your cached object is of a class with no
methods etc… and distinct from the current Type class.

Fred

thanks for your answer, Fred. it’s really a pain, do you know the
reason for that? wouldn’t a simple class check be enough,
like in java?

Not really. The problem is that after each request rails tears down
the classes it has loaded and guts them (and then unsets the
corresponding constant), so your cached object is of a class with no
methods etc… and distinct from the current Type class.

Fred

On Jun 24, 9:04 pm, Pepe J. [email protected]
wrote:

thanks for your answer, Fred. it’s really a pain, do you know the
reason for that? wouldn’t a simple class check be enough,
like in java?

The problem is that technically the two classes really are different.
The convenience of the automatic reloading does have some drawbacks.
If you can get your cache to be wiped at the end of the request cycle
(see config.to_prepare etc…, or mark the code handling the cache as
reloadable) then you would also be ok (but your cache would
effectively be wiped for each request).

Fred