Caching problems in ASP.NET 2.0 beta 2

G

Gavin Pollock

Is anyone using Caching (HttpRuntime.Cache) in Whidbey? Not sure if there's
another newsgroup for this though since it's still beta....

I'm having issues running a system built on 1.1 in a 2.0 environment...
Simple (I think!!) use of the Cache as below,

BOSContext bosContext = new BOSContext();

StringBuilder Html = new StringBuilder();


if (bosContext.Context.Cache[cacheKey] == null ||
!(bosContext.Context.Cache[cacheKey] is StringBuilder))
{
if (xNav == null)
throw new Exception("Side Menu not initialised");
Html.Append("<TABLE cellSpacing='0' cellPadding='0' width='100%'
border='0' class='" + cssClassTable + "'>");
xNav.MoveToRoot();
xNav.MoveToFirstChild();
DisplayTree(xNav, 0);
Html.Append("</TABLE>");
System.Web.Caching.CacheDependency dep = new
System.Web.Caching.CacheDependency(_Filename);
bosContext.Context.Cache.Insert(cacheKey, Html, dep,
DateTime.Now.AddMinutes(15), System.Web.Caching.Cache.NoSlidingExpiration);
}
Html = ((StringBuilder) bosContext.Context.Cache[cacheKey]);

writer.WriteLine(Html.ToString()); //**

And the system is crashing on the //** line with "Object reference not set
to an instance of an object.". I would've thought that the check in the
first line would capture if the StringBuilder was null and instantiate it
there!
 
G

Gavin Pollock

To further question things.... I am getting random Object not found
Exceptions every now and then when running my code. Various objects are set
up to retrieve data in the way below, and occasionally they crash! I put in
the debug code below, and the exception thrown was "orig cache null-cache
null-". Does anyone have any idea how this can be possible!?

Thanks for any light that can be shed!

public static DataSet GetChambersDataSet()

{

string strDebug = "";
BOSContext bosContext = BOSContext.Current;
if (bosContext.Context.Cache[ChamberDataSetCacheKey] == null)
{
strDebug = "orig cache null-";
BOSDataProvider dp = BOSDataProvider.Instance();
DataSet ds = dp.GetChambersDataSet();
if (ds == null)
strDebug += "ds null-";
bosContext.Context.Cache.Insert(ChamberDataSetCacheKey, ds,
null,DateTime.Now.AddHours(1),System.Web.Caching.Cache.NoSlidingExpiration);
}
if (bosContext.Context.Cache[ChamberDataSetCacheKey] == null)
strDebug += "cache null-";
else if (!(bosContext.Context.Cache[ChamberDataSetCacheKey] is DataSet))
strDebug += "cache type:" +
bosContext.Context.Cache[ChamberDataSetCacheKey].GetType();
if (bosContext.Context.Cache[ChamberDataSetCacheKey] == null)
throw new Exception(strDebug);
return (DataSet)bosContext.Context.Cache[ChamberDataSetCacheKey];
}
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top