On Dec 16, 4:12 am, Vikrant Chaudhary <[email protected]> wrote:
> Hi, I just wanted some clarification on this.
>
> In production mode, while I know that object instance variables are
> local to the object and so to the request, but is this same with class
> variables and class instance variables or are they shared between
> requests?
>
> I have this question, because I know that classes are cached in
> production mode. But what does this mean? Like, classes are
> initialised and cached at the start of the server (and so are class
> variables and class level instance variables) and are persistent in
> the memory throughout, or it's like, just class definitions are cached
> (so they are not read every time from the disk), and they are re-
> initialised for every request, so that every request has its own set?

I believe that the classes actually do stay around, but trying to use
them to pass messages is a Bad Idea. There's too many ways for any
changes to get lost - a subsequent request might go to a different
worker, the worker with the value might get killed (by hitting memory
limits, or just things like Passenger's idle timeout, etc). And they
*definitely* go away in development mode, of course.

Note that the typical use of class variables in most of the Rails
source is as a cache of values that should stay constant throughout
execution, which avoids the issue entirely by only setting values
once.

--Matt Jones

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to