title: Are Thread.current[] values and class level attributes safe to use in rails?
body: <p>I have a particular problem I'm trying to solve in a rails 3 app, and the two common solutions that I'm seeing are these:</p>
  
  <p><code>Thread.current[:something] = value</code></p>
  
  <p>and</p>
  
  <pre><code>class Foo
    cattr_accessor :bar
  end
  
  Foo.bar = value
  </code></pre>
  
  <p>Are these methods of data storage (and the corresponding retrieval) safe across multiple users making a request to my rails app, at the same time?</p>
  
  <p>I'm concerned about Thread.current, because a web server could use a single thread to serve up multiple requests, right? Or is there something in the way rails handles threads to prevent problems when using Thread.current? I see <a href="https://github.com/collectiveidea/acts_as_audited" rel="nofollow">Acts As Current</a> uses Thread.current to store the current user, so that gives me hope... but I want authoritative confirmation.</p>
  
  <p>I'm also concerned about class level attributes in a production environment, because I would expect rails to cache class objects in memory, for performance reasons. Does a class level attribute get re-used across requests? or is it safe due to something that rails does to handle class attributes across requests? again, i would like authoritative confirmation of this.</p>
  
  <p>... this app uses Ruby 1.9.2@p180, with Rails 3.0.9</p>