2011年8月23日 星期二

[.NET] 清除快取 Cache.Remove

最近用到cache發現裡面沒有支援Clear() 方法,只好用迂迴的方法抓出所有的Cache.Keys
再一個一個去做Cache.Remove()

裡面是C#寫的範例。




        for( int i=0;i < Cache.Count ; i++ )
        {
            IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();

            string name = CacheEnum.Key.ToString();  
   
            if( Cache[name] != null )
            {    
                Cache.Remove(name);
            }
        }

沒有留言:

張貼留言