none
The expire time for HttpContext.Current.Cache RRS feed

  • Question

  • hi,

        I'm doing a Web Api project, and deployed at IIS in Windows 2008 R2, want to use HttpContext.Current.Cache to store some data. The expire time is 1 day. But the data will be remove in an hour. I didn't restart the IIS or change the files. Is it my fault or I can't use HttpContext.Current.Cache to store data in a longe time(such as 1 day).

            public static void AddCenterData(List<CenterInfo> ls)

            {

                if (ls == null || ls.Count == 0)

                {

                    return;

                }

                List<CenterInfo> centerCache = HttpContext.Current.Cache[CENTERCACHEKEY] as List<CenterInfo>;

                if (centerCache == null)

                {

                    int expireTime = GetExpireMinute();

                    HttpContext.Current.Cache.Insert(CENTERCACHEKEY,
    MergeCenterList(ls,null), null, DateTime.Now.AddMinutes(expireTime),
    System.Web.Caching.Cache.NoSlidingExpiration);

                }

                else

                {

                    HttpContext.Current.Cache[CENTERCACHEKEY] = MergeCenterList(ls,centerCache);

                }

            }

    Thursday, August 14, 2014 2:18 AM

Answers

  • Hi,

    Timeout has Session Timeout and Idle Timeout.  Session timeout is set from web.config and from iis too. Idle timeout only set from iis.

    The idle timeout determines if, and if so after how many minutes of idle time an AppPool is recycled. Recycling the AppPool frees resources but also means that all cached data (compiled version of ASP.NET applications etc.) of sites that run under that AppPool need to be regenerated when the site is requested again (this can take up to several minutes).

    Setting the Application IdleTimeout property within IIS

    You can set the IdleTimeout property within your Application Pool settings in IIS to avoid your actual application timing out. The default value is 20 minutes. You can find instructions on changing this property here.

    The session timeout setting determines how long a session is valid.

    Setting the SessionState Timeout within your web.config

    You can update the timeout property of your Session State (if that is what is actually timing out) within your web.config file in the <sessionState> element as shown below (default of 20 minutes shown below):

    <configuration>
       <system.web>
          <sessionState mode="InProc" timeout="20"/></sessionState>
       </system.web>
    </configuration>

    For more information, you could refer to:

    http://blogfornet.com/2013/06/timeout-settings-in-iis-and-web-config/

    http://forums.asp.net/t/1887538.aspx?Setting+Idle+time+out+time+in+AS+NET

    So, you could check the IdleTimeout property within IIS.

    Regards

    • Marked as answer by FrankYuan_1 Monday, August 18, 2014 9:28 AM
    Friday, August 15, 2014 9:31 AM
    Moderator

All replies

  • Hi,

    Timeout has Session Timeout and Idle Timeout.  Session timeout is set from web.config and from iis too. Idle timeout only set from iis.

    The idle timeout determines if, and if so after how many minutes of idle time an AppPool is recycled. Recycling the AppPool frees resources but also means that all cached data (compiled version of ASP.NET applications etc.) of sites that run under that AppPool need to be regenerated when the site is requested again (this can take up to several minutes).

    Setting the Application IdleTimeout property within IIS

    You can set the IdleTimeout property within your Application Pool settings in IIS to avoid your actual application timing out. The default value is 20 minutes. You can find instructions on changing this property here.

    The session timeout setting determines how long a session is valid.

    Setting the SessionState Timeout within your web.config

    You can update the timeout property of your Session State (if that is what is actually timing out) within your web.config file in the <sessionState> element as shown below (default of 20 minutes shown below):

    <configuration>
       <system.web>
          <sessionState mode="InProc" timeout="20"/></sessionState>
       </system.web>
    </configuration>

    For more information, you could refer to:

    http://blogfornet.com/2013/06/timeout-settings-in-iis-and-web-config/

    http://forums.asp.net/t/1887538.aspx?Setting+Idle+time+out+time+in+AS+NET

    So, you could check the IdleTimeout property within IIS.

    Regards

    • Marked as answer by FrankYuan_1 Monday, August 18, 2014 9:28 AM
    Friday, August 15, 2014 9:31 AM
    Moderator
  • Thanks. It has worked when I set Idle Timeout.
    Monday, August 18, 2014 9:28 AM