How do I clear the server cache in asp.net? I have found out that there are two kinds of the cache. There is the browser cache and the server cache. I have done some searching but I have yet to find a clear, step-by-step guide for clearing the server cache using asp.net (or not).
(update) I just learned that the code-behind for this is in VB - Visual Basic (dot net).
add this code on page load event ..that is http headers to clear cache.
System.Web.HttpRuntime.UnloadAppDomain() - restarts web application, clears cache, resets css/js bundles
You could loop through all the cache items and delete them one by one:
Syntax Correction for ASP.NET 4.5 C#
There is a problem with iteration: it's not thread safe. If you are iterating, and the cache gets accessed from another thread, you might be getting an error. The probability of this is low, but it's a problem with high load applications. FYI, some cache implementations don't even provide iteration methods.
Also, if you are clearing your cache items, you don't want to clear everything from every part of the app domain, but just what's related to you.
When I faced this problem, I solved it by adding a custom CacheDependency to all my cache entries.
This is how the CacheDependency is defined:
You'll need to remove the items you've added to the cache: