Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>request</code> is a global scope, confined to the page request (i.e. thread safe), that lives for the duration of that page request. So it's bad practice in the same way that global variables are a bad practice, but of a short lived duration. I think of it as throwing the data up in the air or over the fence in the situation you described, where any other code can just pluck out of mid air. </p> <p>So for your situation it's probably just fine - add some useful reference at the point of consumption perhaps about where the data's being placed into the <code>request</code> scope in the first place. That stated, if you are going back to the same source method each time , consider caching inside whatever function is responsible creating that object therein (e.g. <code>getVote()</code>) And, you could use the request scope for that as such: </p> <pre><code>&lt;cfparam name="request.voteCache" default="#structNew()#"/&gt; &lt;cffunction name="getVote" output="false" access="public" returntype="any"&gt; &lt;cfargument name="voteId" type="string" required="true"/&gt; &lt;cfif structKeyExists(request.voteCache, arguments.voteId)&gt; &lt;cfreturn request.voteCache[arguments.voteId]&gt; &lt;/cfif&gt; &lt;!--- otherwise get the vote object ---&gt; &lt;cfset request.voteCache[arguments.voteId] = vote&gt; &lt;cfreturn vote&gt; &lt;/cffunction&gt; </code></pre> <p>Downside is if something else changes the data during the request you'll have a stale cache, but it appears you don't expect any changes during the execution. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload