cache expiring prematurely


Tony Hsieh


So I have a asp page that displays the results of a database query
that takes 3 minutes to run. I want to cache this dataset for 10
hours so I don't have to perform the 3 minute query every time someone
goes to the page. The code I use is:

if (Cache[TableCacheName] == null) {
mainConnection = new
SqlDataAdapter mainDA = new
SqlDataAdapter(weeklyQuery, mainConnection);
DataSet daWeekly = new DataSet();
mainDA.SelectCommand.CommandTimeout = 900;
mainDA.Fill(daWeekly, "Weekly");
//i want the cache to expire in 10 hours
Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);

The problem I've been having is that the dataset is not staying in my
cache for more than an hour even though I have expliciting set its
absolute expiration time to be 10 hours from now. My server also has
plently of memory. I don't know whats going wrong. Is there some
setting in IIS thats killing the cache? This has been extremely
frustrating and any help would be greatly appreciated. Thanks so




Mark Fitzpatrick

It very well could be. IIS could be closing out the application, which it
normally does after the last session closes. Then the ASP.Net garbage
collection will kick in and clean up unused items. You could try upping the
session timeout to something ridiculously high as the application won't
expire until the last session has been destroyed, and a typical session
lasts about 20 minutes.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage