Link to home
Start Free TrialLog in
Avatar of curmudgeon42
curmudgeon42

asked on

CFLOCK and Persistent Components

I am working on a new CFMX coding strategy.  In order to put less strain on SQL Server 2000, i'm writing some components that essentially manage a section of my database, such as a Product component.  These components would be loaded into the Server or Application scope, and would keep queries loaded.  In this way, I won't have to hit the product database table everytime, I just have to call Server.ProductManager.getAllProducts() or whatever.  My question:  what sort of concerns does this situation raise in regards to CFLOCK.  When I'm writing the query, do I have to lock it?  When I'm reading?  What if I do an INSERT or UPDATE and the re-load the query.  Does that need a lock?  If so, what level of locking do I need?  Please note that this is CFMX i'm referring to, which seems to be a bit friendlier w/ locking.
ASKER CERTIFIED SOLUTION
Avatar of danrosenthal
danrosenthal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdillon
cdillon

I agree with dan, let coldfusion cache it for you if you want to use the same query over and over.  Other ways to speed things up: stored procedures, cf's query of a query (for small result sets), make sure you have indexes built for the right fields, cfstructs can sometimes be used in place queries if you pre-populate it with query results and finally optimization of the sql code (using a query optimizer if it's available).
I assume this is related to your other question concerning application caching of queries. The wording of your question this time sheds a bit more light on the issue, I might not have been understanding what you were doing before...

As you saying that your are executing a query from within your CFC and simply copying the result set into the application scope? And if so, are you then saying that when you want to refresh the data, you are re-running the query and then re-copying it into the application scope?

If so, you are not doing yourself any good at all. There is no benefit whatsoever to doing it this way. Using a natively cached query will not only be easier, but will be faster because it eliminates the locking issues.

I was under the impression that you were going to be using the CFC to update the cached data on a row by row basis. In other words, on an update to the db you would both update the cached data and the database at the same time. Keeping the cache "synchronized" so to speak. In that scenerio, then there is a benefit. But if you are not doing that, and are simply refreshing the entire cache when the data is stale, then there is no point in it. You should just use query caching.

Heath