caching - ASP.NET session 状态提供程序的 Azure 命名缓存设置?

标签 caching azure session-timeout session-state

我们正在尝试更改 Azure 中的 ASP.NET session 状态超时,并注意到 ASP.NET session 过期方式与命名缓存设置之间存在脱节。更改 Azure 自定义 session 状态提供程序的 web.config sessionState 超时属性是否足够,或者我们是否需要更改服务配置中的命名缓存设置以影响 session 超时?

根据 MSDN,HttpSessionState.Timeout 属性是 session 状态提供程序终止 session 之前请求之间允许的时间量(以分钟为单位)。这意味着在每个带有 SessionID 的请求之后,所有 Session 对象都会获得新的生命周期。

我们的 Windows Azure ASP.NET 应用程序由两个生产实例支持,并配置为通过 Windows Azure 缓存的 session 状态提供程序维护分布式共置缓存中的 session 状态。以下是配置自定义 session 状态提供程序的 web.config 文件片段:

    <!-- 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>

以上设置定义于 ASP.NET Session State Provider Configuration Settings (Windows Azure Caching) 。我们使用默认的 dataCacheClientName。默认缓存和任何其他命名缓存在 Web 角色属性的缓存选项卡上配置。 GUI 提供了一种友好的方式来维护命名缓存设置,这些设置以极不可读的方式存储在所选服务配置的 .cscfg 文件中。请注意默认缓存的逐出策略、过期类型和生存时间属性。这些属性定义于 How to Use Windows Azure Caching 。它们意味着每个缓存对象都有自己的生命周期,而 Session 对象应该全部保留,直到 ASP.NET Session 过期。我是否需要更改命名缓存设置才能将 sessionState 超时延长到 60 分钟,或者无论默认的命名缓存设置如何, session 提供程序都会执行正确的操作吗?如果我还需要调整命名缓存设置,它们应该是什么?

最佳答案

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

In Shared Caching, expiration is always Absolute and there is no way to set a default expiration time. Items in Shared Caching expire after 48 hours. However, you can use the Put and Add methods to set explicit expiration times in code. Note that the ASP.NET providers automatically use these overloads to provide explicit timeouts for session state and output caching. In either case, when your cache size exceeds the limits of your Shared Caching offering, the least recently used items in the cache are evicted.

关于caching - ASP.NET session 状态提供程序的 Azure 命名缓存设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16868228/

相关文章:

javascript - 强制刷新客户端浏览器

c - 线程的缓存在退出时是否刷新到主内存?

Javascript iframe 缓存问题

azure - 通过 REST API 获取 iothub 注册设备

c# - 有没有办法更改 azure 函数的 blob 绑定(bind)中的 blob 路径?

Tomcat集群问题-session超时-in负载均衡

javascript - ASP.NET session 无法自行更新

c - 是否可以绕过多核处理器中的 L1 缓存

java - 如何让 session 不超时?

发布函数时未返回 Azure Functions V2 Http 错误代码内容