title: renaming session variables to variable scope in coldfusion to limit race conditions
body: <p>I've been working with some code that makes use of session data that is quite old.</p>
  
  <p>In multiple areas throughout the site we call </p>
  
  <pre><code>#session.userdetails.profile.firstname#
  </code></pre>
  
  <p>or we pass in a session variable or collection of session variables throughout various templates.</p>
  
  <p>From time to time we have observed that we have some issues with processing the data.</p>
  
  <p>So after reading copious amounts of information on the use of CFLOCK, I'm wondering whether it would be smarter to do the following:</p>
  
  <p>Instead of processing <code>&lt;cflock&gt;</code> around these variables when they are used throughout the templates would it be smarter to set them into the variables scope under new names so they can be called on the additional templates that may be calling the data?</p>
  
  <p>We make use of Fusebox 4 for our framework, so by setting the session vars into in variables in the model / controller we would them minimize our chances of race conditions?</p>
  
  <pre><code>&lt;cflock scope="session" type="readonly" timeout="10"&gt;
      &lt;cfset variables.firstname = session.userdetails.profile.firstname &gt;
  &lt;/cflock&gt;
  </code></pre>
  
  <p>Then throughout the templates because we have established a lock higher up in the chain and the variable is now <code>#variables.firstname#</code> would that minimize the chances of a race condition? Rather than writing the variable <code>#session.userdetails.profile.firstname#</code> throughout our templates?</p>
  
  <p>Sorry if this is considered such a silly question, but I'm just trying to work out a simplified way of making use of these variables as we are noticing that the data when retrieved from the session data isn't always as accurate as we are hoping for.</p>