清除 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);
            }
        }

猜你喜欢

转载自www.cnblogs.com/xiaoruilin/p/9890331.html
今日推荐