Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable asp.net cache

Is there any way to disable Cache (System.Web.Caching.Cache, not OutPut cache for aspx page) on web.config or global.asax or else somehow?

like image 808
Alexandre Avatar asked Oct 11 '22 09:10

Alexandre


1 Answers

From MSDN,

Cache API Configuration Settings

You can configure the application's cache API in your Web.config file. As with the page output cache, application hosters can set configuration properties in the Machine.config file and lock cache configuration settings for all applications. The application cache API is configured in the CacheSection.

You can specify application cache API configuration settings by assigning values to attributes such as DisableExpiration and DisableMemoryCollection within the configuration file's CacheSection.

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

Word of caution: If the DisableMemoryCollection property is set to true, the cache does not attempt to collect unused items. Use caution when using this setting, as disabling memory collection can quickly lead to Out of Memory conditions for the application.

you can set it in the web.config or do this programatically,

// 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);   
like image 157
coder net Avatar answered Dec 13 '22 23:12

coder net