清除 System.Web.Caching.Cache 以"xxx"开头的缓存

 

public static void ClearStartCache(string keyStart)
        {
            List<string> cacheKeys = new List<string>();
            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
            var cacheEnum=_cache.GetEnumerator();
            while (cacheEnum.MoveNext())
            {
                string keyStr = cacheEnum.Key.ToString();
                if (keyStr.StartsWith(keyStart))
                {
                    cacheKeys.Add(keyStr);
                }
            }
            foreach (string cacheKey in cacheKeys)
            {
                _cache.Remove(cacheKey);
            }
        }

 

posted @ 2018-11-01 17:04  三瑞  阅读(490)  评论(0编辑  收藏  举报