/// <summary> /// /// </summary> /// <param name="cacheDataKey"></param> /// <returns></returns> private ArrayList AddDictionary(Neusoft.FrameWork.Models.CacheDataType cacheDataKey, object[] funParam) { try { Neusoft.FrameWork.Management.CacheManager dataConfigManager = new Neusoft.FrameWork.Management.CacheManager(); if (cacheRefreshingFlag.ContainsKey(cacheDataKey) == false) { cacheRefreshingFlag.Add(cacheDataKey, true); } cacheRefreshingFlag[cacheDataKey] = true; //数据获取 //添加版本信息 string dataVersion = ""; ArrayList cacheTemp = dataConfigManager.LoadCacheData(cacheDataKey, funParam, out dataVersion); if (cacheTemp == null) { this.error = dataConfigManager.Err; return(null); } //对于参数数据 只需添加首次数据即可 if (cacheDataPool.ContainsKey(cacheDataKey) == false) { cacheDataPool.Add(cacheDataKey, cacheTemp); cacheVersionPool.Add(cacheDataKey, dataVersion); } //缓存参数数据 if (funParam != null) { if (this.AddParamDictionary(cacheDataKey, funParam, cacheTemp) == -1) { return(null); } } return(cacheTemp); } catch (Exception e) { error = e.Message; return(null); } finally { cacheRefreshingFlag[cacheDataKey] = false; } }
/// <summary> /// 获取缓存数据 /// /// ErrCode=NoDataFound 未维护数据 /// ErrCode=NoManagmentFound 未维护数据提取信息 /// ErrCode=PauseCache 暂停了缓存处理 /// ErrCode=MisMatch 需要的数据类型与缓存数据类别不匹配 /// /// </summary> /// <param name="cacheDataKey">数据索引</param> /// <param name="funParam">函数参数</param> /// <param name="t">数据类型</param> /// <returns>成功返回ArrayList数据</returns> public ArrayList GetDictionary(Neusoft.FrameWork.Models.CacheDataType cacheDataKey, object[] funParam, Type t) { //如果当前正在进行数据刷新则等待完成 while (cacheRefreshingFlag.ContainsKey(cacheDataKey) && cacheRefreshingFlag[cacheDataKey]) { continue; } this.error = string.Empty; this.errCode = string.Empty; //有效性判断 根据ErrCode返回不同错误情况 Neusoft.FrameWork.Management.CacheManager dataConfigManager = new Neusoft.FrameWork.Management.CacheManager(); Neusoft.FrameWork.Models.NeuCache cacheInfo = dataConfigManager.GetCacheConfig(cacheDataKey); if (cacheInfo == null) { this.error = dataConfigManager.Err; this.errCode = dataConfigManager.ErrCode; return(null); } bool isRefreshData = true; if (cacheDataPool.ContainsKey(cacheDataKey)) { #region 校验缓存数据是否过时 //校验缓存数据是否过时 bool isDirtyData = this.JudegeIsDirty(cacheDataKey, cacheInfo); if (isDirtyData) { this.RemoveDictionary(cacheDataKey); } else { isRefreshData = false; } #endregion } //获取参数缓存数据 if (isRefreshData == false && funParam != null && funParam.Length > 0) { ArrayList cacheData = this.GetDictionaryFromCache(cacheDataKey, funParam); if (cacheData == null) { //参数缓存数据不存在 仍需要刷新 isRefreshData = true; } else { if (cacheData != null && cacheData.Count > 0 && cacheData[0].GetType() != t) { error = "缓存数据类型不匹配"; errCode = "MisMatch"; return(null); } return(cacheData); } } if (isRefreshData == false) //不需要重新刷新数据 { #region 由缓存内获取数据内 ArrayList cacheData = cacheDataPool[cacheDataKey]; if (cacheData.Count > 0 && cacheData[0].GetType() != t) { error = "缓存数据类型不匹配"; errCode = "MisMatch"; return(null); } return(cacheData); #endregion } else { //根据cacheDataKey获取数据并加入缓存 ArrayList cacheData = AddDictionary(cacheDataKey, funParam); if (cacheData == null) { return(null); } return(cacheData); } }