Application Objects
Copy link to clipboard
Copied
I have an object that I use to process address information. Currently I'm instantiating per request, however, I'd like to move that into an application scope. My concern is that somehow this will adversely affect the my request or session level scope or that somehow if multiple requests occur that the request/session will crosswires somehow.
Copy link to clipboard
Copied
It sounds like you are worried about a threading issue -- without seeing the code if your cfc it is hard to say for sure, but in many cases you should be ok.
If the functions in your CFC only operate on the input arguments you should be fine, if you are doing a lot of read/write in the variables scope in your CFC if it is stored in the application scope, then you might need to lock access to those variables to avoid race conditions. The request scope is per request so there is no worry of issue there - session scope is automatically locked by CF, so you don't need to lock unless you are doing something like session.counter = session.counter + 1 (but that applies always not just in a CFC in an application scope).
This might provide some additional insight: Adam Cameron's Dev Blog: Overlapping requests will not cause a race condition in a CFM's variables s...
Copy link to clipboard
Copied
nak33 wrote:
Currently I'm instantiating per request, however, I'd like to move that into an application scope.
Do you wish to switch from request.someVar to application.someVar? If so, then user-sessions might indeed cross wires. For, if one user instantiates an application-scoped variable, he will have done so for all other current users of the application. It is best in these circumstances to show us the code.

