.NET 使用缓存

    /// <summary>
    /// 获取客户网站发件箱信息
    /// </summary>
    /// <returns></returns>
    public static ECustomerMailServer GetCustomerMailServer()
    {
        ECustomerMailServer _ECustomerMailServer = null;

        if (HttpContext.Current.Cache["CustomerMailServer"] == null)
        {
            int CID = 0;
            int.TryParse(ConfigurationManager.AppSettings["CID"], out CID);
            _ECustomerMailServer = new ECustomerMailServer();
            _ECustomerMailServer = new CustomerMailServerBLL().GetCustomerMailServer(CID);
            HttpContext.Current.Cache.Add("CustomerMailServer", _ECustomerMailServer, new CacheDependency(HttpContext.Current.Server.MapPath("~/web.config")), DateTime.Now.AddMonths(1), TimeSpan.Zero, CacheItemPriority.High, null);
        }
        else
        {
            _ECustomerMailServer = (ECustomerMailServer)HttpContext.Current.Cache["CustomerMailServer"];
        }
        return _ECustomerMailServer;
    }

 

posted @ 2013-05-22 11:34  划破黑夜  阅读(285)  评论(0编辑  收藏  举报