簡體   English   中英

查看System.Web.HttpRuntime.Cache中緩存的數據

[英]View the data cached in System.Web.HttpRuntime.Cache

是否有任何工具可用於查看HttpRunTime緩存中的緩存數據..?
我們有一個Asp.Net應用程序,它將數據緩存到HttpRuntime Cache中。 給定的默認值為60秒,但后來更改為5分鍾。 但感覺緩存的數據在5分鍾之前就會刷新。 不知道底下發生了什么。

有沒有可用的工具或我們如何看到HttpRunTime Cache中緩存的數據....有效期...?
以下代碼用於添加要緩存的項目。

    public static void Add(string pName, object pValue)
    {
    int cacheExpiry= int.TryParse(System.Configuration.ConfigurationManager.AppSettings["CacheExpirationInSec"], out cacheExpiry)?cacheExpiry:60;
    System.Web.HttpRuntime.Cache.Add(pName, pValue, null, DateTime.Now.AddSeconds(cacheExpiry), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
    }


謝謝。

Cache類支持IDictionaryEnumerator來枚舉緩存中的所有鍵和值。

IDictionaryEnumerator enumerator = System.Web.HttpRuntime.Cache.GetEnumerator();
while (enumerator.MoveNext())
{
    string key = (string)enumerator.Key;
    object value = enumerator.Value;
    ...
}

但我不相信有任何官方方式來訪問元數據,如到期時間。

Cache類支持IDictionaryEnumerator來枚舉緩存中的所有鍵和值。 以下代碼是如何從緩存中刪除每個鍵的示例:

List<string> keys = new List<string>();

// retrieve application Cache enumerator
IDictionaryEnumerator enumerator = System.Web.HttpRuntime.Cache.GetEnumerator();

// copy all keys that currently exist in Cache
while (enumerator.MoveNext())
{
    keys.Add(enumerator.Key.ToString());
}

// delete every key from cache
for (int i = 0; i < keys.Count; i++)
{
    HttpRuntime.Cache.Remove(keys[i]);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM