CacheItemRemovedCallback Problems
-
Guys, I am having problems with the use of the CacheItemRemovedCallback event within an ASP.NET/C# website I am building. The below code is from my global.aspx file. The code loads XML/XSL objects into the Cache for later use. I also create a Cache dependency so should any files change which my XML/XSL objects use, the Cache is updated automatically. The code works only when something is removed from the Cache by another aspx file, since the code correctly identifies the HttpContext. However, when one of my files is changed and the RemovedCallback() function is fired, for some reason the Context and the HttpContext are both null. As such my code never has a chance to update the Cache again. Rather it exists "without an error" as soon as I try to use Cache.Insert. Does anyone know if this is a bug in Beta 2, or am I missing something, like the use of a special Context object? Any help greatly appreciated.......... Cheers, Tim. <%@ Import Namespace="System.Xml.Xsl" %> <%@ Import Namespace="System.Xml.XPath" %> <%@ Import Namespace="System.Web.Caching" %> <%@ Import Namespace="CommerceEngine.Common" %> private static CacheItemRemovedCallback onRemove = null; private XPathDocument CommerceListXmlObj; private XslTransform CommerceListXslObj; public void Application_OnStart() { ApplicationConfiguration.OnApplicationStart(Context.Server.MapPath( Context.Request.ApplicationPath )); onRemove = new CacheItemRemovedCallback(this.RemovedCallback); CommerceListXmlObj = new XPathDocument(CommerceEngineConfiguration.CommerceListXmlFilePath); HttpContext.Current.Cache.Insert("CommerceListXmlObj", CommerceListXmlObj, new CacheDependency (CommerceEngineConfiguration.CommerceListXmlFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove ); CommerceListXslObj = new XslTransform(); CommerceListXslObj.Load(CommerceEngineConfiguration.CommerceListXslFilePath); HttpContext.Current.Cache.Insert("CommerceListXslObj", CommerceListXslObj, new CacheDependency(CommerceEngineConfiguration.CommerceListXslFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove ); } public void RemovedCallback(String k, Object v, CacheItemRemovedReason r) { switch(k) { case "CommerceListXmlObj" : CommerceListXmlObj = new </x-turndown>