2

We are trying to change our ASP.NET Session State timeout in Azure and have noticed a disconnect between the way ASP.NET sessions expire and the Named Cache Settings. Will it suffice to change the web.config sessionState timeout property for Azure's custom Session State provider or do we need to change the Named Cache Settings in the service configuration to influence session timeout?

According to MSDN, the HttpSessionState.Timeout property is the amount of time, in minutes, allowed between requests before the session-state provider terminates the session. That means that all Session objects get a new lease on life after each request that bears its SessionID.

Our Windows Azure ASP.NET app is supported by two production instances and configured to maintain Session State in the distributed co-located cache via the Session State Provider for Windows Azure Caching. Here is the web.config file snippet that configures the custom Session State provider:

    <!-- Windows Azure Caching session state provider -->
    <sessionState mode="Custom" customProvider="AFCacheSessionStateProvider">
        <providers>
            <add name="AFCacheSessionStateProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheSessionState"/>
        </providers>
    </sessionState>

    <!-- Windows Azure Caching output caching provider -->
    <caching>
        <outputCache defaultProvider="AFCacheOutputCacheProvider">
            <providers>
                <add name="AFCacheOutputCacheProvider" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheOutputCache" />
            </providers>
        </outputCache>
    </caching>

The above setting are defined at ASP.NET Session State Provider Configuration Settings (Windows Azure Caching). We are using the default dataCacheClientName. The default cache and any other named caches are configured on the Caching tab of the web role properties. A GUI provides a friendly way of maintaining Named Cache Settings that are stored in a highly unreadable manner in the .cscfg file for the selected Service Configuration. Notice the Eviction Policy, Expiration Type and Time to Live properties of the default cache. These properties are defined at How to Use Windows Azure Caching. They imply that each cached object has its own life cycle while Session objects should all persist until the ASP.NET Session expires. Do I need to change the Named Cache Settings in order to extend my sessionState timeout to 60 minutes or will the Session Provider do the right thing regardless of the default Named Cache Settings? If I need to also adjust the Named Cache Settings, what should they be?

4

1 回答 1

0

根据此处找到的文档,Azure 缓存的 ASP.NET 会话状态提供程序显式设置每个对象的过期时间,覆盖配置的缓存过期时间。因此,听起来您只需要担心设置适当的驱逐策略,状态提供者管理到期和生存时间。这是相关的摘录:

在共享缓存中,过期始终是绝对的,无法设置默认过期时间。共享缓存中的项目会在 48 小时后过期。但是,您可以使用 Put 和 Add 方法在代码中设置显式过期时间。请注意,ASP.NET 提供程序自动使用这些重载来为会话状态和输出缓存提供显式超时。在任何一种情况下,当您的缓存大小超过共享缓存产品的限制时,缓存中最近最少使用的项目将被逐出。

于 2013-09-25T15:08:50.530 回答