By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Application Cache Remove Callback Issue

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> public static void RefreshCache(String key, Object item,
CacheItemRemovedReason reason)
{
XmlDocument doc = new XmlDocument();
doc.Load(path);

cache.Insert ("Test", doc, new CacheDependency (path),
Let's modify this code to see where the problem lies. According to you, the
application gets this far.
so do this before the insert
if(path == null || path.Lenth == 0)
throw new Exception("attempting to load null path");

if(cache == null)
throw new Exception("Attempting to manipulate Invalid cache");

cache.insert....

if it makes it past that point and you can't figure out what the error is
post a follow-up

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Glenn" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com... 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.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.