Would it be considered “thread safe” to store a class level instance invariable (i.e. MyClass.foo) as long as I clear it at the end of the request? For example setting the value in a before_filter and clearing it in an after_filter?
My understanding is if I do not clear it.. it will exist for future requests which I do not want. But if I set it and clear it.. is that good enough? Or could two requests overlap and cause a collision and mutated data?
This is probably a really bad idea as it might bleed information between requests and sessions. If you need a short-term cache that’s thread-safe, you can always spike methods on to the
requestobject that’s created for you.If you’re trying to push session information down into the global context of a model then you’re going against the MVC design pattern. Any information a model needs should be passed in in a well-defined manner, especially as this makes testing orders of magnitude simpler and more reliable.