Thursday, July 14, 2022

How to create and clear cache in ASP.NET C# Or in IIS

 

1. How to clear cache in asp.net C# (clear specified cache)

string cacheKey = "TestCache";

//Add cache
       Cache.Add(cacheKey"Cache content"nullDateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.High, null);

Cache.Remove(cacheKey);//C# clear cache

 

2. How to clear all caches in asp.net C#

IDictionaryEnumerator allCaches = HttpRuntime.Cache.GetEnumerator();

while (allCaches.MoveNext())
       {
              Cache.Remove(allCaches.Key.ToString());
       }
       Response.Write("Remove all caches!");


OR

>In IIS Goto HTTP Responses

>Click on 'set common headers'

> Click on 'Expire web content' and click OK

reference:- https://mohamedradwan.com/2010/12/26/caching-static-files-js-files-css-and-images-in-iis-7/



No comments:

Post a Comment