Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / May 2004

Tip: Looking for answers? Try searching our database.

Application level caching and callbacks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe User - 26 May 2004 12:47 GMT
I'm trying to put a xml file in the Cache to be shared for the whole
application. Whenever I change the xml file I need to refresh the Cache,
so I put this code on the global.asax.cs file. It add a callback to
reload the xml file, but it seems that the callback doesn't work. ¿What
I'm doing wrong?

------------------------------------------------------------
private static Cache _cache = null;
private static string _path = null;
protected void Application_Start(Object sender, EventArgs e) {
   _cache = this.Context.Cache;
   _path = Server.MapPath("xml/traduccion.xml");               
   LoadXML();
}
private void LoadXML() {           
   XmlDocument xmlDoc = new XmlDocument();
   xmlDoc.Load(_path);
   _cache.Insert("xmlDoc", xmlDoc,
   new CacheDependency(_path),
   Cache.NoAbsoluteExpiration,
   Cache.NoSlidingExpiration,
   CacheItemPriority.Default,
   new CacheItemRemovedCallback(reload_Callback));
}
private void reload_Callback(string key, Object item,
                                         CacheItemRemovedReason reason){
   LoadXML();
}
Alvin Bruney [MVP] - 27 May 2004 04:55 GMT
you have a couple things wrong here. roughly the fix would be to keep a
reference to the callback (which you are throwing away) like so

app_start event handler
onRemove = new CacheItemRemovedCallback(this.reload_Callback);

//later
then you call your insert
_cache.Insert("xmlDoc", xmlDoc,
   new CacheDependency(_path),
   Cache.NoAbsoluteExpiration,
   Cache.NoSlidingExpiration,
   CacheItemPriority.Default,
   new CacheItemRemovedCallback(reload_Callback));

Signature

Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok

> I'm trying to put a xml file in the Cache to be shared for the whole
> application. Whenever I change the xml file I need to refresh the Cache,
[quoted text clipped - 22 lines]
>    LoadXML();
> }
Joe User - 30 May 2004 11:29 GMT
> you have a couple things wrong here. roughly the fix would be to keep a
> reference to the callback (which you are throwing away) like so
[quoted text clipped - 10 lines]
>     CacheItemPriority.Default,
>     new CacheItemRemovedCallback(reload_Callback));

You mean this?

_cache.Insert("xmlDoc", xmlDoc,
     new CacheDependency(_path),
     Cache.NoAbsoluteExpiration,
     Cache.NoSlidingExpiration,
     CacheItemPriority.Default,
     new CacheItemRemovedCallback(onRemove));

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.