using System.Collections.Generic;
using System.Web;
using System.Web.Caching;

namespace Stat.Cache
{
    class Company : ICompany
    {
        #region ICompany 成员

        public IList<Stat.Model.Company> Get()
        {
            string cName = "CompanyInfo";
            if (HttpContext.Current.Cache.Get(cName) == null)
            {
                // 建立缓存依赖项，如果文件发生变化，删除缓存
                string _Ctxt = @"\CacheTxt\Company.txt";
                Methods.CreatFile(HttpContext.Current.Server.MapPath(_Ctxt));
                CacheDependency dep = new CacheDependency(HttpContext.Current.Server.MapPath(_Ctxt));

                IList<Stat.Model.Company> list = BLL.Company.GetTop(1, 1);
                if (list != null && list.Count > 0)
                {
                    HttpContext.Current.Cache.Insert(cName, list, dep, System.DateTime.MaxValue, System.TimeSpan.FromHours(24.0), CacheItemPriority.Normal, null);
                }
                return list;
            }
            return (IList<Stat.Model.Company>)HttpContext.Current.Cache.Get(cName);//从缓存中读取
        }

        #endregion
    }
}
