cache expiring prematurely

Discussion in 'ASP .Net' started by Tony Hsieh, Aug 18, 2004.

  1. Tony Hsieh

    Tony Hsieh Guest

    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
     
    Tony Hsieh, Aug 18, 2004
    #1
    1. Advertisements

  2. 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
     
    Mark Fitzpatrick, Aug 19, 2004
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.