Application Cache Remove Callback Issue


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.
 
Ad

Advertisements

A

Alvin Bruney [MVP]

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 said:
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):
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top