/// <summary> /// 释放,开始立即更新所有缓存 /// </summary> public void Dispose() { if (DoFlush) { AliMessageQueue.OperateQueue(); } }
/// <summary> /// 启动线程轮询 /// </summary> public void Run() { do { AliMessageQueue.OperateQueue(); Thread.Sleep(_sleepMilliSeconds); } while (true); }
private void BaseContainerBag_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var containerBag = (IBaseContainerBag)sender; var mqKey = AliMessageQueue.GenerateKey("ContainerBag", sender.GetType(), containerBag.Key, "UpdateContainerBag"); //加入消息队列,每过一段时间进行自动更新,防止属性连续被编辑,短时间内反复更新缓存。 AliMessageQueue mq = new AliMessageQueue(); mq.Add(mqKey, () => { //var containerCacheStrategy = CacheStrategyFactory.GetContainerCacheStrategyInstance(); var containerCacheStrategy = CacheStrategyFactory.GetObjectCacheStrategyInstance().ContainerCacheStrategy; var itemCacheKey = ContainerHelper.GetItemCacheKey(containerBag); containerBag.CacheTime = DateTime.Now;//记录缓存时间 //cacheKey形如:Container:Com.Alibaba.MP.Containers.AccessTokenBag:wx669ef95216eef885 containerCacheStrategy.UpdateContainerBag(itemCacheKey, containerBag); }); }