public void TestAll() { var mq = new LimeMessageQueue(); var count = mq.GetCount(); var key = DateTime.Now.Ticks.ToString(); //Test Add() var item = mq.Add(key, () => WeixinTrace.Log("测试LimeMessageQueue写入Key=A")); Assert.AreEqual(count + 1, mq.GetCount()); //var hashCode = item.GetHashCode(); //Test GetCurrentKey() var currentKey = mq.GetCurrentKey(); Assert.AreEqual(key, currentKey); //Test GetItem var currentItem = mq.GetItem(currentKey); Assert.AreEqual(currentItem.Key, item.Key); Assert.AreEqual(currentItem.AddTime, item.AddTime); //Test Remove mq.Remove(key); Assert.AreEqual(count, mq.GetCount()); }
/// <summary> /// 释放,开始立即更新所有缓存 /// </summary> public void Dispose() { if (DoFlush) { LimeMessageQueue.OperateQueue(); } }
/// <summary> /// 启动线程轮询 /// </summary> public void Run() { do { LimeMessageQueue.OperateQueue(); Thread.Sleep(_sleepMilliSeconds); } while (true); }
public void RemoveFromCache(string key) { if (string.IsNullOrEmpty(key)) { return; } LimeMessageQueue.OperateQueue(); //延迟缓存立即生效 _cache.KeyDelete(key); //删除键 }
private void BaseContainerBag_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var containerBag = (IBaseContainerBag)sender; var mqKey = LimeMessageQueue.GenerateKey("ContainerBag", sender.GetType(), containerBag.Key, "UpdateContainerBag"); //获取对应Container的缓存相关 //加入消息列队,每过一段时间进行自动更新,防止属性连续被编辑,短时间内反复更新缓存。 LimeMessageQueue mq = new LimeMessageQueue(); mq.Add(mqKey, () => { var containerCacheStragegy = CacheStrategyFactory.GetContainerCacheStragegyInstance(); var cacheKey = ContainerHelper.GetCacheKey(this.GetType()); containerBag.CacheTime = DateTime.Now;//记录缓存时间 containerCacheStragegy.UpdateContainerBag(cacheKey, containerBag); }); }