Saving parsed XML in the application scope in Coldfusion 8.0

Posted on 2008-11-11
Last Modified: 2013-12-24

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

Question by:OSAIT
    LVL 36

    Accepted Solution

    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)


    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
    Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now