asp.net - 禁用asp.net缓存

标签 asp.net caching

有什么方法可以禁用 web.config 或 global.asax 上的缓存(System.Web.Caching.Cache,而不是 aspx 页面的 OutPut 缓存)或以其他方式禁用?

最佳答案

从 MSDN,

缓存 API 配置设置

您可以在 Web.config 文件中配置应用程序的缓存 API。与页面输出缓存一样,应用程序托管者可以在 Machine.config 文件中设置配置属性并锁定所有应用程序的缓存配置设置。应用缓存 API 在 CacheSection 中配置。

您可以通过为配置文件的 CacheSection 中的 DisableExpiration 和 DisableMemoryCollection 等属性分配值来指定应用程序缓存 API 配置设置。

If the DisableMemoryCollection property is set to true, calls to the cache-related API will have no effect.



注意事项:如果 DisableMemoryCollection 属性设置为 true,则缓存不会尝试收集未使用的项目。使用此设置时要小心,因为禁用内存收集会很快导致应用程序出现内存不足的情况。

您可以在 web.config 中设置它或以编程方式执行此操作,
// Get the application configuration file.
   System.Configuration.Configuration config =
   System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");


   System.Web.Configuration.CacheSection cacheSection =
   (System.Web.Configuration.CacheSection)config.GetSection(
    "system.web/caching/cache");

  cacheSection.DisableMemoryCollection = true;

  // Save the configuration file.
  config.Save(System.Configuration.ConfigurationSaveMode.Modified);   

关于asp.net - 禁用asp.net缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6843343/

相关文章:

c# - 多个 RadioButtonList 并插入到 SQL 中

c# - 缓存 mysql 结果 C#

c# - Appfabric 缓存错误代码 <ERRCA0016> :SubStatus<ES0001>

asp.net - 从 Linux 应用服务计划中托管的 .NET Core Azure Web 应用连接到 SQL Server 2016 时出错

javascript - 在 ASP.NET MVC 应用程序中渲染 iframe 内的部分 View

javascript - 如何将文本框值传递给 JavaScript?

caching - 英特尔酷睿 i7 的缓存规范

javascript - 无法让 Angular 应用程序在 MVC 布局中工作

android - 缓存路由在 Skmaps 上被清除

performance - 戈朗 : right way to store map structure in lru cache