Clear maintained cache forcefully which stored the website of users' data.
How to clear cache in ASP.NET MVC?
106020-Jan-2023
Updated on 04-Jun-2023
Home / DeveloperSection / Forums / How to clear cache in ASP.NET MVC?
Clear maintained cache forcefully which stored the website of users' data.
Aryan Kumar
04-Jun-2023There are a few ways to clear cache in ASP.NET MVC.
1. Clear the browser cache
The easiest way to clear cache is to clear the browser cache. This will remove all cached files from the browser, including any cached pages from your ASP.NET MVC application. To clear the browser cache, follow these steps:
2. Clear the output cache
You can also clear the output cache for a specific controller action or for the entire application. To clear the output cache for a specific controller action, use the [OutputCache] attribute. The [OutputCache] attribute allows you to specify the duration of the cache, the location of the cache, and other options. For example, the following code will cache the output of the Home controller action for 10 minutes:
Code snippet
To clear the output cache for the entire application, you can use the following code:
Code snippet
3. Clear the memory cache
The memory cache is used to store frequently accessed data in memory. This can improve performance by reducing the number of times that data needs to be retrieved from the database or other slow data sources. To clear the memory cache, you can use the following code:
Code snippet
4. Use a cache clearing tool
There are a number of third-party tools that can be used to clear cache in ASP.NET MVC. These tools can be useful for clearing large amounts of cache or for clearing cache from multiple servers.
Here are some of the popular cache clearing tools:
Amrita Bhattacharjee
21-Jan-2023Hi,
To answer this specific question,first of all we need to know that cache is specific object type in ASP.NET.We can use or implement several methods for removing cache but the most easy way would be the using of following syntax-
var staleItem = Url.Action('Action', “YourController”, new
{
Id = model.Id,
area = 'areaname';
});
Response.RemoveCacheItem(staleItem);