all groups > dotnet xml > march 2005 >
You're in the

dotnet xml

group:

How to keep XSLs in Memory?


How to keep XSLs in Memory? Alexis
3/21/2005 6:59:04 AM
dotnet xml:
Hello,

I'm working on a project that uses over a hundred XLSs for transforming xml
documents. The project consists of several webservices (IIS) calling a few
dlls. This dlls make the business logic and are the ones that do the
transformation, so the XLSs are used by these dlls. Right now we have the
XSLs files on hard disk. This means there is lots of reading from disk. Since
reading from disk is much slower than reading from memory I am looking for a
way to keep them in memory.
Any Ideas?
Will IIS cache them? How? (Keep in mind they are used by the dlls)

I also was thinking simple work around. Using a RAM Disk, but it seems
Windows 2003 server does not support RAM Disks.

Any help?

Thanks.
Re: How to keep XSLs in Memory? Alexis
3/22/2005 6:31:05 AM
Thanks Oleg

Can you tell me how to cache the XslTransform?
Can you send me sample code of the first call that do the cache and the
other calls that will use the cache objets.?

Thanks again
Alexis

[quoted text, click to view]
Re: How to keep XSLs in Memory? Alexis
3/22/2005 9:37:04 AM
Thanks again.
I read the article but they are using the Application object to store the
cached objects. But as I said in the first question the transformation is
done by a Dll so I don't have access to the Application Object there.

Do you know of a method of caching without using the Application object?

More specific caching from a Dll.

You can read again the first question to understand better the problem I am
having.

Thanks again.

[quoted text, click to view]
Re: How to keep XSLs in Memory? Ross Presser
3/22/2005 1:20:54 PM
[quoted text, click to view]

There's no RAM disk driver *shipped* with Windows 2000 and above, but there
are many third-party RAM disk drivers available that will work. Seek (on
Re: How to keep XSLs in Memory? Oleg Tkachenko [MVP]
3/22/2005 1:40:18 PM
[quoted text, click to view]

Just cache loaded XslTransform objects in cache instead of loading them
for each request. XslTransform.Transform() method is thread-safe, so
once XslTransaform object is created and Load() method has been called,
it's safe to run Transform() method in many threads.

--
Oleg Tkachenko [XML MVP, MCP]
Re: How to keep XSLs in Memory? Ross Presser
3/22/2005 2:16:56 PM
[quoted text, click to view]

Your original post said the DLL will be called by a web service. So there
ultimately is an Application object available, which your DLL can access
with this:

HttpContext.Current.ApplicationInstance

Or, if you don't mind if your XSL objects are occasionally flushed from the
cache and will be reloaded, you can make more direct use of the ASP.NET
Cache this way:

Re: How to keep XSLs in Memory? Oleg Tkachenko [MVP]
3/22/2005 4:52:37 PM
[quoted text, click to view]

If you are talking about ASP.NET, you can use standard caching methods.
Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt09.asp
for a sample.

--
Oleg Tkachenko [XML MVP, MCP]
Re: How to keep XSLs in Memory? Oleg Tkachenko [MVP]
3/23/2005 1:19:22 PM
[quoted text, click to view]

Quick and dirty cache is just plain Hashtable. You can make it better
using WeakReferences.
Otherwise take a look at the "Caching Application Block"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/caching1.asp

--
Oleg Tkachenko [XML MVP, MCP]
Re: How to keep XSLs in Memory? Alexis
3/24/2005 7:01:04 AM
Oleg Thanks again I really appreciate your help
But you are getting me to nowhere. Graet book index but little contect.
Thanks anyway for trying.

[quoted text, click to view]
Re: How to keep XSLs in Memory? Alexis
3/24/2005 7:07:03 AM
Ross Thankyou very much.

I have not have time to try it yet but it make a lot of sense. I was just
wondering how efficient it may be. The whole purpose of keeping the XSL files
or objects in memory is to improve performance. Do you know if accessing the
HttpContext from a dll will have some impact on performance?

Thanks a lot again I really appreciate your help.


[quoted text, click to view]
Re: How to keep XSLs in Memory? Alexis
3/24/2005 7:11:04 AM
I am not really a fan of using third-party software but thanks any way for
the tip.

[quoted text, click to view]
Re: How to keep XSLs in Memory? Ross Presser
3/24/2005 12:27:23 PM
[quoted text, click to view]

Well, the thing of it is, where do you expect the DLL to cache it? You need
something that has persistence between invocations of your DLL, and the
easiest answer to that is to let ASP.NET handle it. And the way to access
ASP.NET's cache is through HttpContext.Current.

I could be wrong about this, and you might want to check the other dotnet
Re: How to keep XSLs in Memory? Alexis
3/25/2005 7:27:03 AM
What I want to keep in memory are XSLs files used for transformation not the
data so the contenct don't change, but I don't think ASP.NET will cache XSL
files. See my original goal is to keep XSL files in memory instead of having
to read them from disk on every request

[quoted text, click to view]
Re: How to keep XSLs in Memory? Ross Presser
3/29/2005 2:35:31 PM
[quoted text, click to view]

ASP.NET's Application object, or Cache object, will cache ANY object, with
Re: How to keep XSLs in Memory? Alexis
3/30/2005 7:05:07 AM
I would like to try to cache the xsl objects them.
Can you provide me with a code sample? I have not used cahing in yet.

[quoted text, click to view]
Re: How to keep XSLs in Memory? Ross Presser
4/1/2005 4:58:29 PM
[quoted text, click to view]

Hope you don't mind VB.NET ...

' this function will look in the ASP.NET cache for an XSLTransform;
' if it's there, it will return it;
' if it's not, it will call CreateTheXSLT() to create it.
Public Function GetXSLTObject(ByVal key As String) _
As System.Xml.Xsl.XslTransform
' get a handle to the ASP.NET cache
Dim c As Web.Caching.Cache
c = HttpContext.Current.Cache

Dim x As System.Xml.Xsl.XslTransform
If c.Item(key) Is Nothing Then
' it wasn't in the cache ...
' create it fresh, then put it in the cache
x = CreateTheXSLT(key)
' sliding expiration of 2 hrs ...
' if we don't use it for 2 hrs, ASP.NET is allowed to
' purge it from the cache
c.Add(key, x, Nothing, Nothing, _
System.TimeSpan.FromHours(2), _
Caching.CacheItemPriority.Normal, _
Nothing)
Return x
Else
' yaay, it was in the cache ... return it
x = c.Item(key)
Return x
End If

AddThis Social Bookmark Button