cache expiring prematurely

T

Tony Hsieh

Hi,

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
SqlConnection(@"SERVER=X;DATABASE=Y;Trusted_Connection=Yes");
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.Insert(TableCacheName,
daWeekly.Tables["Weekly"],null,DateTime.Now.AddHours(10),
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
much.

-Tony
 
M

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top