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

namespace Stat.Cache
{
    class Message : IMessage
    {
        /// <summary>
        /// 反馈
        /// </summary>
        /// <param name="s">条数</param>
        /// <returns></returns>
        public IList<Stat.Model.Message> Get(int s)
        {
            string cName = "Message_" + s.ToString();
            if (HttpContext.Current.Cache.Get(cName) == null)
            {
                // 建立缓存依赖项，如果文件发生变化，删除缓存
                string _Ctxt = @"\CacheTxt\Message.txt";
                Methods.CreatFile(HttpContext.Current.Server.MapPath(_Ctxt));
                CacheDependency dep = new CacheDependency(HttpContext.Current.Server.MapPath(_Ctxt));

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