asp.net - Azure 的 HttpRuntime.Cache 设置?

标签 asp.net .net azure caching memory

我正在使用 HttpRuntime.Cache 在 Azure 上进行内存缓存。

问题是内存已满 - 然后它达到了 Azure 90% 的百分比限制,Azure 认为该角色不健康并重新启动它 - 导致整个站点瘫痪。

现在我找到了 EffectivePercentagePhysicalMemoryLimit 属性,它在 Azure 上似乎设置为 98%,因此高于 90% 的“不健康”限制。

  • 如何更改 HttpRuntime.Cache 的此限制?该属性是只读的。
  • 是否可以将 Azure 自动重启百分比调整得更高一点?
  • 对于使用内存缓存还有其他推荐设置吗?我还应该使用其他类(class)吗?我能找到的与Azure结合的信息很少。如果数据需要在多个实例之间保持一致,大多数文章都会讨论单独的缓存服务。

需要明确的是:我想要内存缓存 - 我不需要通过 Redis 进行共享缓存,因为数据不太需要保持一致。

最佳答案

您可以使用 cache ElementpercentagePhysicalMemoryUsedLimit 属性更改 EffectivePercentagePhysicalMemoryLimit在你的 web.config 中

<configuration>
  <system.web>
    <caching>
      <cache percentagePhysicalMemoryUsedLimit="60" />
    </caching>
  </system.web>

The EffectivePercentagePhysicalMemoryLimit property can be set with the percentagePhysicalMemoryUsedLimit attribute of the cache Element for caching (ASP.NET Settings Schema) element in the application's configuration file. If the percentagePhysicalMemoryUsedLimit attribute is not set, the cache algorithm determines the maximum size of the cache, and the EffectivePercentagePhysicalMemoryLimit property is calculated.

您可以在文档中获取更多信息:Cache.EffectivePercentagePhysicalLimit

<小时/>

另一个选项是禁用 Azure 自动重启机制。它被称为Proactive Auto Heal您可以通过将 WEBSITE_PROACTIVE_AUTOHEAL_ENABLED 设置为 False 来禁用它:

  1. 转至 Portal.azure.com,然后转至您想要禁用该功能的网络应用。
  2. 在“设置”下,转到“应用程序设置”。
  3. 在“应用设置”下添加“WEBSITE_PROACTIVE_AUTOHEAL_ENABLED”并将其设置为“False”。
  4. 就是这样!主动自动修复已禁用。

enter image description here

关于asp.net - Azure 的 HttpRuntime.Cache 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46941877/

相关文章:

c# - 在 C# 中是 bool 读/写原子

c# - 什么是NullReferenceException,如何解决?

.net - Silverlight 4.0 和 WCF 客户端代理 - 如何创建和关闭实例

即使在 web.config 之后,Azure Web 应用程序也不会将 http 重定向到 https

azure - Ansible 安装所有必需的 Azure 模块

c# - .NET、分层架构和 MongoDB - 使用什么作为 ID?

asp.net - 集中式 ASP.NET 错误处理 : <customErrors> vs. Application_Error。可以同时使用吗?

reactjs - 当后端托管在 Azure 上时,create-react-app 代理请求失败并显示 404

c# - SignalR 连续消息传递

javascript - 我可以对变量调用 ".log"