Caching data

D

David Gagné

Hi,
I'm using ASP on Windows 2K. I'm NOT using ASP.Net. I have static data in an
XML file that I would like to cache. Based on my idea explained below, is it
an approach that should scale correctly? Considering that the cache will be
used extensively, will this create a bottleneck?

My idea is:
In the application_OnStart(), I load the xml file and store the xml string
in an application variable:
sub application_OnStart()
...
myXmlDOM.Load("myfile.xml")
Application("myXMLString") = myXmlDOM.xml
' Would have been insteresting to store the parsed xml in the
application
' but it returns an error saying the object can't be stored in
application variable
' because it has appartment threaded behaviors.
' Set Application("myXML") = myXmlDOM doesn't work
...
end sub

Then I create an asp file (cache.asp) that has functions to get information
from this xml string.
function getName(theID)
...

set oDs = Server.CreateObject("MSXML2.DOMDocument")
...
if oDs.loadXML(Application("myXMLString")) then
...
xpath = ... theID
' Get the value using selectSingleNode(xpath)
...
end if
set oDs = nothing
end function

function getID(theName)
...

set oDs = Server.CreateObject("MSXML2.DOMDocument")
...
if oDs.loadXML(Application("myXMLString")) then
...
xpath = ... theName
' Get the value using selectSingleNode(xpath)
...
end if
set oDs = nothing
end function

Thanks for you advise,
David.
 
M

Mark Schupp

There is a thread-safe version of the XMLDom object
(Msxml2.FreeThreadedDOMDocument) that you could store in the Application
object. I am not familiar with the performance or concurrency issues
associated with it.
 
C

Chris Hohmann

David Gagné said:
Hi,
I'm using ASP on Windows 2K. I'm NOT using ASP.Net. I have static data in an
XML file that I would like to cache. Based on my idea explained below, is it
an approach that should scale correctly? Considering that the cache will be
used extensively, will this create a bottleneck?

My idea is:
In the application_OnStart(), I load the xml file and store the xml string
in an application variable:
sub application_OnStart()
...
myXmlDOM.Load("myfile.xml")
Application("myXMLString") = myXmlDOM.xml
' Would have been insteresting to store the parsed xml in the
application
' but it returns an error saying the object can't be stored in
application variable
' because it has appartment threaded behaviors.
' Set Application("myXML") = myXmlDOM doesn't work
...
end sub

Then I create an asp file (cache.asp) that has functions to get information
from this xml string.
function getName(theID)
...

set oDs = Server.CreateObject("MSXML2.DOMDocument")
...
if oDs.loadXML(Application("myXMLString")) then
...
xpath = ... theID
' Get the value using selectSingleNode(xpath)
...
end if
set oDs = nothing
end function

function getID(theName)
...

set oDs = Server.CreateObject("MSXML2.DOMDocument")
...
if oDs.loadXML(Application("myXMLString")) then
...
xpath = ... theName
' Get the value using selectSingleNode(xpath)
...
end if
set oDs = nothing
end function

Thanks for you advise,
David.

Use the thread safe version to save the parsed document to an
Application variable:

MSXML2.FreeThreadedDOMDocument.4.0

As for bottlenecks, I imagine that you will actually see quite an
improvement in performance by using a cached document. Let me know how
it turns out.

Notes:
1. In the future, please indicate what version of MSXML you are using.
2. Consider using version specific ProgID's, as version independent
ProgID's have been deprecated
3. Consider using "NewParser":

DOM.setProperty("NewParser",True)

HTH
-Chris Hohmann
 
D

dlbjr

David,

I have done the same in the past.
I have found the dom object to be a little sluggish
How large is the xml?.

-dlbjr

Discerning resolutions for the alms
 
D

David Gagné

Not very big, let say 10K.
How big when you started having problems?
Where you using MSXML 4.0, the free threaded version and the "NewParser" ?

What do you mean "sluggish"?

Thanks,
David.
 
D

dlbjr

Yes I use 4
I found under heavy traffic the Dom parsing seem to lag client response.

This may give you an idea.

I store ID and Value data in an Application Level array.
I build a dynamic drop down from the array and set the selected item per
client request.

Much faster than using any XML as Application string.

HTH
-dlbjr

Discerning resolutions for the alms
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top