PC Review


Reply
Thread Tools Rate Thread

Caching in Class Libraries (c#)

 
 
Mat
Guest
Posts: n/a
 
      12th Jan 2004
I have a class library in which I need to access a XML Document often
which is stored as a text xml file. Obviously, I therefore would like
to cache this XML Document as reading this into an XML Document type
each time its required wouldn't be efficient. Does anyone have any
pointers on this.

There is a Cache object in System.Web but by default this isn't
available to class libraries, it it worth adding the reference into
the component?

I've also looked into the Microsoft Blocks and see that there is an
Cache Block which may also help be in my quest.
(http://msdn.microsoft.com/library/de...chingBlock.asp)

However, having never done anything along these lines, any experience
is gratefully welcome.

Cheers in advance

Mat
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      12th Jan 2004

>I have a class library in which I need to access a XML Document often
>which is stored as a text xml file. Obviously, I therefore would like
>to cache this XML Document as reading this into an XML Document type
>each time its required wouldn't be efficient. Does anyone have any
>pointers on this.


Can the XML source change while the application is running? If not, is
there any reason why you don't simply keep a reference to the
XmlDocument object for as long as you need it?



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Magnus Lidbom
Guest
Posts: n/a
 
      13th Jan 2004

"Mat" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a class library in which I need to access a XML Document often
> which is stored as a text xml file. Obviously, I therefore would like
> to cache this XML Document as reading this into an XML Document type
> each time its required wouldn't be efficient. Does anyone have any
> pointers on this.
>
> There is a Cache object in System.Web but by default this isn't
> available to class libraries, it it worth adding the reference into
> the component?


Such caches are mostly useful in a stateless environment, such as the web,
where they are used to simulate state. In your case you should probably use
a singleton. A good tutorial on singletons in C#, written by Jon Skeet, can
be found here: http://www.yoda.arachsys.com/csharp/singleton.html

Regards /Magnus



> I've also looked into the Microsoft Blocks and see that there is an
> Cache Block which may also help be in my quest.
>

(http://msdn.microsoft.com/library/de...-us/dnpag/html
/CachingBlock.asp)
>
> However, having never done anything along these lines, any experience
> is gratefully welcome.
>
> Cheers in advance
>
> Mat




 
Reply With Quote
 
Magnus Lidbom
Guest
Posts: n/a
 
      13th Jan 2004

"Mattias Sjögren" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> >I have a class library in which I need to access a XML Document often
> >which is stored as a text xml file. Obviously, I therefore would like
> >to cache this XML Document as reading this into an XML Document type
> >each time its required wouldn't be efficient. Does anyone have any
> >pointers on this.

>
> Can the XML source change while the application is running? If not, is
> there any reason why you don't simply keep a reference to the
> XmlDocument object for as long as you need it?


I'd say that's the way to do it even if it may change. If the file in
question
lives on the filesystem you can simply use System.IO.FileSystemWatcher and
basic thread synchronization to keep it up to date. If the document lives
somewhere else you can use a System.Threading.Timer and some custom code to
monitor for updates.

Regards /Magnus

>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.












 
Reply With Quote
 
Magnus Lidbom
Guest
Posts: n/a
 
      13th Jan 2004

"Mattias Sjögren" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> >I have a class library in which I need to access a XML Document often
> >which is stored as a text xml file. Obviously, I therefore would like
> >to cache this XML Document as reading this into an XML Document type
> >each time its required wouldn't be efficient. Does anyone have any
> >pointers on this.

>
> Can the XML source change while the application is running? If not, is
> there any reason why you don't simply keep a reference to the
> XmlDocument object for as long as you need it?


I'd say that's the way to do it even if it may change. If the file in
question
lives on the filesystem you can simply use System.IO.FileSystemWatcher and
basic thread synchronization to keep it up to date. If the document lives
somewhere else you can use a System.Threading.Timer and some custom code to
monitor for updates.

Regards /Magnus

>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.












 
Reply With Quote
 
Magnus Lidbom
Guest
Posts: n/a
 
      13th Jan 2004
Sorry about the double-post. Outlook Express went postal when i clicked
send, complaing about not being able to delete the file, and my kneejerk
reaction was to press send again.

/Magnus


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Class Libraries Paolo Microsoft C# .NET 0 21st Aug 2008 11:17 PM
ConfigurationManager Class Unavailable in Class Libraries =?Utf-8?B?TWlrZQ==?= Microsoft ASP .NET 2 4th Oct 2006 05:33 PM
Windows Mobile 2003 class libraries versus Windows Mobile 5 class libraries Thore Berntsen Microsoft Dot NET Compact Framework 1 26th Jun 2006 05:03 PM
Web Application, Web Service, Class Libraries, and StrongNameIdentityPermissionAttribute Class Mythran Microsoft ASP .NET 1 24th Aug 2005 12:17 AM
Class libraries =?Utf-8?B?QWx2byB2b24gQ29zc2VsIEk=?= Microsoft C# .NET 2 11th Jul 2005 02:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 PM.