If you cache pages in a HttpHandler with
_context.Response.Cache.SetCacheability(HttpCacheability.Public);
_context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(180));
is it possible to clear a certain page from the cache?
is it possible to Clear a certain page from the Cache?
Yes:
HttpResponse.RemoveOutputCacheItem("/pages/default.aspx");
You can also use Cache dependencies to remove pages from the Cache:
this.Response.AddCacheItemDependency("key");
After making that call, if you modify Cache["key"], it will cause the page to be removed from the Cache.
In case it might help, I cover caching in detail in my book: Ultra-Fast ASP.NET.
more simple one...
public static void ClearCache()
{
Cache cache = HttpRuntime.Cache;
IDictionaryEnumerator dictionaryEnumerators = cache.GetEnumerator();
foreach (string key in (IEnumerable<string>) dictionaryEnumerators.Key)
{
cache.Remove(key);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With