Esempio n. 1
0
 /// <summary>
 /// 測量寫入的時間及記憶體
 /// </summary>
 /// <param name="cache"></param>
 private static void MeasureSetMemoryAndTimeByRedisProtobuf(string cacheName, IDatabase cache)
 {
     System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();
     sh.Start();
     MemWatch mw = new MemWatch(true);
     List<UserMenuInfo> menus = GetTestData();
     Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
     mw.Start();
     foreach (var menu in menus)
     {
         cache.SetProtobuf("PF-" + menu.PRG_NO, menu, TimeSpan.FromDays(1));
     }
     mw.Stop();
     Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
     sh.Stop();
     Console.WriteLine(string.Format("CacheName:{0},Set-Milliseconds:{1}", cacheName, sh.ElapsedMilliseconds));
 }
Esempio n. 2
0
 /// <summary>
 /// 測量寫入的時間及記憶體
 /// </summary>
 /// <param name="cache"></param>
 private static void MeasureSetMemoryAndTime(string cacheName, ObjectCache cache)
 {
     System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();
     sh.Start();
     MemWatch mw = new MemWatch();
     List<UserMenuInfo> menus = GetTestData();
     Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
     mw.Start();
     CacheItemPolicy policy = new CacheItemPolicy();
     policy.AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddDays(1));
     foreach (var menu in menus)
     {
         cache.Set(menu.PRG_NO, menu, policy);
     }
     mw.Stop();
     Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
     sh.Stop();
     Console.WriteLine(string.Format("CacheName:{0},Set-Milliseconds:{1}", cacheName, sh.ElapsedMilliseconds));
 }