G
Guest
Hi,
I have a config XML file that I am using from the application cache. I have configured the entry with a remove callback to re-populate cache automatically when the XML file changes. All is well until the XML file is changed. The cached item is being removed as I would expect, but the remove callback is not firing at all, hence a NullReferenceException is being raised when I try to access the cache object.
Please see code snippet below from global.asax (.NET Framework 1.1 and VS.NET 2003 on IIS 5 web server):
private static Cache cache;
private static string path;
protected void Application_Start(Object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
cache = Context.Cache;
path = Context.Server.MapPath ("Test.xml");
doc.Load(path);
cache.Insert ("Test", doc, new CacheDependency (path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshCache));
}
public static void RefreshCache(String key, Object item, CacheItemRemovedReason reason)
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
cache.Insert ("Test", doc, new CacheDependency (path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshCache));
}
Any ideas why this doesn't work ?
Thanks,
Glenn.
I have a config XML file that I am using from the application cache. I have configured the entry with a remove callback to re-populate cache automatically when the XML file changes. All is well until the XML file is changed. The cached item is being removed as I would expect, but the remove callback is not firing at all, hence a NullReferenceException is being raised when I try to access the cache object.
Please see code snippet below from global.asax (.NET Framework 1.1 and VS.NET 2003 on IIS 5 web server):
private static Cache cache;
private static string path;
protected void Application_Start(Object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
cache = Context.Cache;
path = Context.Server.MapPath ("Test.xml");
doc.Load(path);
cache.Insert ("Test", doc, new CacheDependency (path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshCache));
}
public static void RefreshCache(String key, Object item, CacheItemRemovedReason reason)
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
cache.Insert ("Test", doc, new CacheDependency (path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshCache));
}
Any ideas why this doesn't work ?
Thanks,
Glenn.