Link to home
Start Free TrialLog in
Avatar of OSAIT
OSAIT

asked on

Saving parsed XML in the application scope in Coldfusion 8.0

Hello,

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?

Thanks,
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'))>
	</cfif>
</cflock>
 
<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>
		</cfloop>
	</cflock>
</select>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

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 OSAIT
OSAIT

ASKER

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.