/// <summary> /// 判断数据是否过时 /// </summary> /// <param name="cacheDataKey">数据索引</param> /// <returns></returns> private bool JudegeIsDirty(Neusoft.FrameWork.Models.CacheDataType cacheDataKey, Neusoft.FrameWork.Models.NeuCache cacheInfo) { string cacheVersion = cacheVersionPool[cacheDataKey]; if (cacheInfo.DataVersion.ToString() == cacheVersion) { return(false); } else { return(true); } }
/// <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); } }