缓存方法一

namespace BLL
{
    public class CacheManager
    {
        //private string cacheKey;
        private const string XMLPATH = "~Config/CacheDepencyFile.xml";
        private const string PARENTNODE = "Cache";
        private const string PATH = "BLL";
        private static string xmlMapPath = HttpContext.Current.Server.MapPath(XMLPATH);
        private static object obj = new object();
        private Hashtable cacheHash;
        private XmlDocument document;
       
        /// <summary>
        /// 索引(key-value)
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public virtual string this[string index]
        {
            get {
                if (cacheHash[index] == null)
                    return string.Empty;
                return cacheHash[index] as string;
            }
            set {
                cacheHash[index] = value;
            }
        }

        /// <summary>
        /// set key-value
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public virtual void Hash(string key,string value)
        {
            cacheHash[key] = value;
        }

        /// <summary>
        /// protected constuctor
        /// </summary>
        protected CacheManager()
        {
            cacheHash = new Hashtable();
            document = new XmlDocument();
        }

        /// <summary>
        /// Global Access
        /// </summary>
        /// <param name="cacheEntity"></param>
        /// <returns></returns>
        public static CacheManager GetCacheManagerEntity(string cacheEntity)
        {
            CacheManager cm = LRCache.Get(cacheEntity) as CacheManager;
            if (cm == null)
            {
                lock (obj)
                {
                    if (cm == null)
                    {
                        string classEntity = PATH + "." + cacheEntity;
                        cm = Assembly.Load(PATH).CreateInstance(classEntity) as CacheManager;
                        cm.LoadData();
                        CacheDependency depency = new CacheDependency(xmlMapPath);
                        LRCache.Permanent(cacheEntity, cm, depency);
                    }
                }
            }
            return cm;
        }

        /// <summary>
        /// provide child class
        /// </summary>
        protected DataView dvData;
        protected virtual void LoadData(){ }
    }
}

 

 

namespace BLL
{
    public class EdusManager : CacheManager
    {
        protected override DataView LoadData()
        {

            dvData = LoadEdus() as DataView;

            return dvData ;
        }

        //加载学历
        protected DataView LoadEdus()
        {
            DataView dv = null;
            try
            {
                DataSet ds;
                PassPortBLL objBll = new PassPortBLL();
                ReturnValue rtn = objBll.GetEduList(out ds);
                if (rtn.Result == 1)
                    dv = ds.Tables[0].DefaultView;
            }
            catch (Exception ex)
            {
                LogManager.WriteTextLog("BLL", "EdusManager", "LoadEdus", ex.Message);
            }
            return dv;
        }
    }
}

//call

CacheManager  cm = CacheManager GetCacheManagerEntity("EdusManager ") as CacheManager ;

DataView dv = cm.dvData;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值