Alexandre
Alexandre

Reputation: 13328

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?

Upvotes: 6

Views: 1655

Answers (1)

coder net
coder net

Reputation: 3475

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);   

Upvotes: 4

Related Questions