HighTechTalks DotNet Forums  

.net 2.0 cache problem

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss .net 2.0 cache problem in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Neil Stevens
 
Posts: n/a

Default .net 2.0 cache problem - 12-15-2005 , 05:11 PM






hi,

ill try and make this as brief as i can, i am having some problems with caching with VS.NET 2005 and .NET 2.0.

i have the following code which loads the content of an xml file into a hashtable and then caches the hashtable for later use.

private static void LoadResource(ResourceManagerType resourceType, Hashtable target, String language, String cacheKey)
{
String filePath = HttpContext.Current.Server.MapPath("~/Themes/Languages/" + language + "/{0}");
switch (resourceType)
{
case ResourceManagerType.String:
filePath = String.Format(filePath, "Resources.xml");
break;
case ResourceManagerType.Image:
filePath = String.Format(filePath, "Images.xml");
break;
}
CacheDependency dp = new CacheDependency(filePath);
XmlDocument d = new XmlDocument();
try
{
d.Load(filePath);
}
catch
{
return;
}
foreach (XmlNode n in d.SelectSingleNode("root").ChildNodes)
{
if (n.NodeType != XmlNodeType.Comment)
{
switch (resourceType)
{
case ResourceManagerType.String:
case ResourceManagerType.Image:
if (target[n.Attributes["name"].Value] == null)
{
target.Add(n.Attributes["name"].Value, n.InnerText);
}
else
{
target[n.Attributes["name"].Value] = n.InnerText;
}
break;
}
}
}
DateTime cacheUntil;
if (language == EnigmaConfiguration.GetConfig().DefaultLanguage)
{
cacheUntil = DateTime.MaxValue;
}
else
{
cacheUntil = DateTime.Now.AddHours(1);
}
HttpContext.Current.Cache.Insert(cacheKey, target, dp, cacheUntil, TimeSpan.Zero); // this sometimes fails to insert into the cache and the resultant check for cacheKey in the cache returns null
}

My question is simply this, is there a problem with cacheing in .net 2.0, it seems that on some occasions cache.Insert(...) fails to insert the data into the cache and result in a null reference exception. I never had this problem before in .net 1.1 or .net 1.0.

Any help would be appreciated

Regards
Neil

Reply With Quote
  #2  
Old   
Manso
 
Posts: n/a

Default RE: .net 2.0 cache problem - 03-06-2006 , 03:58 PM






Hi Neil, you don't seem to be alone with this problem. Have you managed to
find out what it was? I'm experiencing a similar problem but with the
HttpRuntime.Cache (which supposedly is the same...although Rob Howard
suggests there's a perf. penalty when using it which suggests there's some
difference...).

A few posts regarding this has been posted today.

Thanks,
Manso

"Neil Stevens" wrote:

Quote:
hi,

ill try and make this as brief as i can, i am having some problems with caching with VS.NET 2005 and .NET 2.0.

i have the following code which loads the content of an xml file into a hashtable and then caches the hashtable for later use.

private static void LoadResource(ResourceManagerType resourceType, Hashtable target, String language, String cacheKey)
{
String filePath = HttpContext.Current.Server.MapPath("~/Themes/Languages/" + language + "/{0}");
switch (resourceType)
{
case ResourceManagerType.String:
filePath = String.Format(filePath, "Resources.xml");
break;
case ResourceManagerType.Image:
filePath = String.Format(filePath, "Images.xml");
break;
}
CacheDependency dp = new CacheDependency(filePath);
XmlDocument d = new XmlDocument();
try
{
d.Load(filePath);
}
catch
{
return;
}
foreach (XmlNode n in d.SelectSingleNode("root").ChildNodes)
{
if (n.NodeType != XmlNodeType.Comment)
{
switch (resourceType)
{
case ResourceManagerType.String:
case ResourceManagerType.Image:
if (target[n.Attributes["name"].Value] == null)
{
target.Add(n.Attributes["name"].Value, n.InnerText);
}
else
{
target[n.Attributes["name"].Value] = n.InnerText;
}
break;
}
}
}
DateTime cacheUntil;
if (language == EnigmaConfiguration.GetConfig().DefaultLanguage)
{
cacheUntil = DateTime.MaxValue;
}
else
{
cacheUntil = DateTime.Now.AddHours(1);
}
HttpContext.Current.Cache.Insert(cacheKey, target, dp, cacheUntil, TimeSpan.Zero); // this sometimes fails to insert into the cache and the resultant check for cacheKey in the cache returns null
}

My question is simply this, is there a problem with cacheing in .net 2.0, it seems that on some occasions cache.Insert(...) fails to insert the data into the cache and result in a null reference exception. I never had this problem before in .net 1.1 or .net 1.0.

Any help would be appreciated

Regards
Neil

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.