Saving parsed XML in the application scope in Coldfusion 8.0


Our application is developed in Coldfusion 8.0 and uses XML files to store configuration information, such a list of journals offered on our site.  We have previously loaded these files dynamically every time they were needed by calling XMLParse and storing it in standard variable scope memory.  However, this was using a considerable amount of server memory considering an XML file approximately 50 kb in size was being loaded for every page view.  We receive up to 10,000 hits per hour.

I'd like to store these XML files in shared application memory to reduce the amount of memory being used for each request.  To do this, I load the XML file into an application variable if that variable has not yet been defined.  Please see the attached code snippet.

This all works fine... for about 20 minutes.  After about 20 minutes, the application variable seems to be overwritten with garbage.  The appropriate calls to XML element stop working, and instead I get errors such as "journal[i].link is not defined in application.osajournals" or null null The error occurred on line -1.

I have implemented a locking scheme, as shown in the code snippet, but this does not solve the issue.  I have also tracked calls to the XMLParse function in the database, and the XMLParse is NOT being called multiple times.  There is no other code that tries to write to the parsed XML object.  It seems the XML object variable gets corrupted some other way.

Can anyone assist with this?

Josh D.
<cflock name="xml_journal_lock" type="exclusive" timeout="10">
	<cfif NOT isdefined("application.osajournals") OR IsDefined("URL.varReload")>	
		<cfset application.osajournals = XMLParse(expandpath('/include/xml/journallist.xml'))>
<select name="Journals">
	<cflock name="xml_journal_lock" type="readonly" timeout="10">
		<cfloop from="1" to="#ArrayLen(application.osajournals.journal)#" index="i">
			<option value="#application.osajournals.journal[i].link.xmltext#">#application.osajournals.journal[i].displayname.xmltext#</option>

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nothing obvious but it's probably a locking conflict you would try the cflock without the name param and use scope=Application" instead or increase the timeout

perhaps an alternative would be to use a request variable in application.cfm

<cfset request.osajournals = XMLParse(expandpath('/include/xml/journallist.xml'))>

<cfloop from="1" to="#ArrayLen(request.osajournals.journal)#" index="i">
<option value="#request.osajournals.journal[i].link.xmltext#">#request.osajournals.journal[i].displayname.xmltext#</option>

request vars reduce server overhead as they are sent with each http request (and don't have locking issues)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OSAITAuthor Commented:
I think because we have many other application variables that aren't being locked, something was getting over written.  The request scope won't help us reduce memory usage because it's created new for each request.

Ultimately, we decided to load the XML into the database first, then use standard database methods to display the information.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.