using System.Web;

namespace Stat.Cache
{
    class RemoveCache : IRemoveCache
    {
        #region ICache 成员
        /// <summary>
        /// 系统重启
        /// </summary>
        public void Restart()
        {
            Methods.ChangeCache(@"\web.config");
        }
        /// <summary>
        /// 清除广告缓存
        /// </summary>
        /// <returns></returns>
        public void RemoveAdCache()
        {
            Methods.ChangeCache(@"\CacheTxt\AD.txt");
        }
        /// <summary>
        /// 清除友情缓存
        /// </summary>
        public void RemoveFrendLinkCache()
        {
            Methods.ChangeCache(@"\CacheTxt\FL.txt");
        }

        public void RemoveCompanyCache()
        {
            Methods.ChangeCache(@"\CacheTxt\Company.txt");
        }

        public void RemoveMessageCache()
        {
            Methods.ChangeCache(@"\CacheTxt\Message.txt");
        }

        public void RemoveNewsCache()
        {
            Methods.ChangeCache(@"\CacheTxt\News.txt");

        }
        public void RemoveNotifyCache()
        {
            Methods.ChangeCache(@"\CacheTxt\Notify.txt");
        }
        public void RemoveSysCache()
        {
            Methods.ChangeCache(@"\CacheTxt\Sys.txt");
        }
        public void RemoveNavigateCache()
        {            
            Methods.ChangeCache(@"\CacheTxt\Navigate.txt");
        }
        public void RemoveWebsiteCache(int webid)
        {
            System.Web.Caching.Cache mycache = HttpRuntime.Cache;
            mycache.Remove("Website_" + webid.ToString());//站点缓存
            mycache.Remove("Statsite_" + webid.ToString());//统计缓存
            mycache.Remove("StatRole_" + webid.ToString());//规则缓存
        }
        /*----------------------------------------------*/

        /// <summary>
        /// 清除系统配置缓存
        /// </summary>
        public void RemoveConfigCache()
        {
            Methods.ChangeCache(@"\CacheTxt\Sys_Config.txt");
        }

        /// <summary>
        /// 清除所有缓存
        /// </summary>
        public void RemoveAllCache()
        {
            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
            System.Collections.IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
            while (CacheEnum.MoveNext())
            {
                _cache.Remove(CacheEnum.Key.ToString());
            }
        }
        /// <summary>
        /// 获取所有的缓存
        /// </summary>
        /// <returns></returns>
        public System.Collections.IDictionaryEnumerator GetAllCache()
        {
            System.Web.Caching.Cache appCache = HttpRuntime.Cache;
            return appCache.GetEnumerator();
        }


        /// <summary>
        /// 清除某栏目文章缓存
        /// </summary>
        /// <param name="columnID"></param>
        public void RemoveColumnCache(int columnID)
        {
            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
            System.Collections.IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
            while (CacheEnum.MoveNext())
            {
                if (CacheEnum.Key.ToString().IndexOf("_Column" + columnID) > -1)
                {
                    _cache.Remove(CacheEnum.Key.ToString());
                }
            }
        }
        /// <summary>
        /// 清除某地区文章缓存
        /// </summary>
        /// <param name="areaID"></param>
        public void RemoveAreaCache(int areaID)
        {
            System.Web.Caching.Cache _cache = HttpRuntime.Cache;
            System.Collections.IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
            while (CacheEnum.MoveNext())
            {
                if (CacheEnum.Key.ToString().IndexOf("_Area" + areaID) > -1)
                {
                    _cache.Remove(CacheEnum.Key.ToString());
                }
            }

        }



        #endregion



    }
}
