/// <summary> /// 操作列队 /// </summary> public static void OperateQueue() { lock (FlushCacheLock) { var mq = new CacheDataMessageQueue(); var key = mq.GetCurrentKey(); //获取最新的Key while (!string.IsNullOrEmpty(key)) { var mqItem = mq.GetItem(key); //获取任务项 mqItem.Action(); //执行 mq.Remove(key); //清除 key = mq.GetCurrentKey(); //获取最新的Key } } }
protected void BaseCacheBindable_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (sender == null) { LogUtility.Cache.ErrorFormat("BaseCacheBindable发生错误,不是BaseCacheBindable类型。当前参数类型:{0}", sender.GetType()); return; } var objCacheData = sender as ICacheData; if (objCacheData == null) { LogUtility.Cache.ErrorFormat("BaseCacheBindable发生错误,没有实现ICacheData接口。当前参数类型:{0}", sender.GetType()); return; } if (objCacheData.Key == null) { LogUtility.Cache.ErrorFormat("BaseCacheBindable发生错误,Key为空。当前参数类型:{0}", sender.GetType()); return; } var mqKey = CacheDataMessageQueue.GenerateKey("SenparcCache", sender.GetType(), objCacheData.Key as string, "UpdateCache"); //获取对应Container的缓存相关 //加入消息列队,每过一段时间进行自动更新,防止属性连续被编辑,短时间内反复更新缓存。 CacheDataMessageQueue mq = new CacheDataMessageQueue(); mq.Add(mqKey, () => { var cacheStragegy = CacheStrategyFactory.GetObjectCacheStrategyInstance(); //var cacheKey = objCacheData.Key; objCacheData.CacheTime = DateTime.Now;//记录缓存时间 cacheStragegy.Set(objCacheData.Key, objCacheData as T); //var cacheKey = ContainerHelper.GetCacheKey(this.GetType()); //containerBag.CacheTime = DateTime.Now;//记录缓存时间 //containerCacheStragegy.UpdateContainerBag(cacheKey, containerBag); }); }