![](/img/trans.png)
[英]How to clear the cache of an asp.net application from another asp.net application on the same server?
[英]How can we clear the server side cache in a button click in an asp.net application?
我對此有一個典型的要求。
我有一個在asp.net 4.0中開發的Web應用程序。 在這個應用程序中,我想在其中一個Web表單中添加一個按鈕,它將執行以下任務:
現在,我知道我們可以通過刪除此處存在的文件手動實現它,
%systemroot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
%systemroot%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
我們需要在刪除臨時文件之前關閉IIS,然后再重新啟動它。 為了避免對緩存文件的任何依賴。
但我想知道如何在Web表單的按鈕單擊事件中實現它。 請幫我解決這個問題。
我目前在我的應用程序中使用以下內容:
public static void ClearAspNetCache(HttpContext context) {
foreach (DictionaryEntry entry in context.Cache) {
context.Cache.Remove((string)entry.Key);
}
}
這是一個可能非常有用的源參考:
如果要從緩存中刪除所有項目,請嘗試使用此選項:
IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator();
while (enumerator.MoveNext())
{
HttpContext.Current.Cache.Remove(enumerator.Key);
}
從HttpContext.Current.Cache中刪除項目不會清除您的IIS緩存。 它是服務器端緩存(由ASP.NET運行時管理),而不是Web服務器緩存。
看看這個鏈接。 http://blogs.msdn.com/b/dougste/archive/2008/08/11/clearing-out-temporary-asp-net-files.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.