When to use application-scoped locking

I am wondering if I need to block some code generated in the application scope. If I create an object, tell userDAO.cfc in the app scope to be available to all pages. Then if I have a method in this object say getUserInfo (userID) to be called in different parts of the application, do I need to block this method?

+1


source to share


1 answer


The short answer is, maybe not.

If this object is created in the application scope from your Application.cfc OnApplicationStart () method, it never changes, and also you will definitely be var for all your variables for all your functions, then you will not need to block access to it.

In this case, OnApplicationStart () does the blocking for you and will not allow anyone to act until this method is created. This is good because it will only allow you to create the item once and make sure it exists before anyone else uses it.

If you instantiate an object from anywhere, like the top of some random page, then yes, you will need to block it here and everywhere by referencing it.



If the object will ever change to another object, or if it retains any state like private or public variables (variables. * Or this. *) That change to other things, you can lock it externally, or you can try lock it inside cfc based on variable.

Finally, if you don't var all your variables ( use Mike Schierberl's varScoper! ), Then you will be changing the state of the object, you should never get to this point, but this is a case of blocking.

Big exceptions for everything, if you are using CF 5 or lower, in which case any access to the shared access area MUST be blocked, and if you are using CF 6 or 6.1 then Application.cfc will not be there.

+4


source







All Articles