What if it is a singleton component? wonât it cause a racing condition issue, since the component stays in memory and another request could affect it?
I guess the only solution for it would be a lockâŚ
Iâd like to complement some information that I think is very important to share on this topic for the ones who donât know it! A very usefull tool to identify this type of scoping issues is Lucees debugger with the âmodernâ template and debugging setting âImplicit variable Accessâ enabled. This is such a rocking awesome tool that helped me a lot already!!! Makes identifying those searching variables a piece of cake, especially because Iâm not that of an expert that I always think of scoping variables on the fly. Nowadays I always run the debugger after a dev day, just to check this scoping issues. To see it in action, do this, and youâll see the magic with your own code:
Run a lucee instance , log into your Lucee Server/Web administrator
Go to âDebuggingâ > âSettingsâ > and set:
âEnable Debuggingâ to âyesâ
Check âImplicit variable Accessâ to enable the information
Go to âDebuggingâ > âTemplatesâ and create a debugging template of type âmodernâ. Give it a name of your choice.
Then create a test.cfm file with the following content:
<cfscript>
public string function setVarsAndDumpScopes() {
// set variables to form scope
form.a=1;
form.b=1;
writeOutput("<div>URL Scope Dump</div>");
writeDump("#url#");
writeOutput("<br><br><div>Form Scope Dump</div>");
writeDump("#form#");
writeOutput("<br><br><div>Variables Scope Dump</div>");
writeDump("#variables#");
writeOutput("<br><br><div>Arguments Scope Dump</div>");
writeDump("#arguments#");
}
// miguels test function
function test(){
var haystack = [1,2,3,4,5,6];
var needle = 3;
var found = arrayFilter(haystack, function(item){
return arguments.item == variables.needle;
});
dump (found);
}
test();
setVarsAndDumpScopes();
writeOutput("<div>Write variable to output without scope name (implicit):</div> ");
writeOutput("a: #a#<br>");
writeOutput("b: #b#<br>");
</cfscript>