.net 删除缓存的key中带有指定字符的方法

   /// <summary>
        /// 删除带有指定字符的缓存
        /// </summary>
        /// <param name="pre"></param>
        public void Refresh(string pre)
        {
            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
            IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
            ArrayList al = new ArrayList();
            while (CacheEnum.MoveNext())
            {
                al.Add(CacheEnum.Key);
            }
            foreach (string key in al)
            {
                if (string.IsNullOrEmpty(pre))
                {
                    _cache.Remove(key);
                }
                else
                {
                    if (key.Contains(pre))
                    {
                        _cache.Remove(key);
                    }
                }
            }
        }
        #endregion

posted on 2016-06-28 17:40  南宇辰  阅读(284)  评论(0编辑  收藏  举报

导航