有什么方法可以禁用 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/