public void CustomerRedisCache() { Model.Customer.CustomerModel customerModel = this.CreateCustomerModel(); Interface.Repository.ICacheRepository cacheManager = DI.Container.Resolve <Interface.Repository.ICacheRepository>(); string cacheKey = Guid.NewGuid().ToString(); cacheManager.Set(cacheKey, customerModel, TimeSpan.FromMinutes(1)); Model.Customer.CustomerModel loadedModel = cacheManager.Get <Model.Customer.CustomerModel>(cacheKey); Assert.AreEqual(loadedModel.CustomerName, customerModel.CustomerName); } // CustomerRedisCache
public void LargeObjectRedisCache() { Model.LargeObject.LargeObjectModel largeObjectModel = this.CreateLargeObjectModel(); largeObjectModel.LargeObjectId = 1; Interface.Repository.ICacheRepository cacheManager = DI.Container.Resolve <Interface.Repository.ICacheRepository>(); string cacheKey = Guid.NewGuid().ToString(); cacheManager.Set(cacheKey, largeObjectModel, TimeSpan.FromMinutes(1)); Model.LargeObject.LargeObjectModel loadedModel = cacheManager.Get <Model.LargeObject.LargeObjectModel>(cacheKey); Assert.AreEqual(loadedModel.Payload, largeObjectModel.Payload); } // LargeObjectRedisCache
private void cacheWrite_Click(object sender, EventArgs e) { // Get the current settings. int minWorker, minIOC; System.Threading.ThreadPool.GetMinThreads(out minWorker, out minIOC); txtResult.Text = string.Empty; txtResult.Text += "minWorker = " + minWorker.ToString() + Environment.NewLine; txtResult.Text += "minIOC = " + minWorker.ToString() + Environment.NewLine; int newSetting = 200; if (System.Threading.ThreadPool.SetMinThreads(newSetting, newSetting)) { // The minimum number of threads was set successfully. txtResult.Text += "Thread pool set to = " + newSetting.ToString() + Environment.NewLine; } else { // The minimum number of threads was not changed. txtResult.Text += "ERROR: Thread pool NOT set"; } int loop = Int32.Parse(txtLoop.Text); Interface.Repository.ICacheRepository cacheManager = DI.Container.Resolve <Interface.Repository.ICacheRepository>(); string cacheKey = largeObjectModel.LargeObjectId.ToString(); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); for (int i = 1; i <= loop; i++) { largeObjectModel.LargeObjectId = i; cacheKey = i.ToString(); cacheManager.Set(cacheKey, largeObjectModel, TimeSpan.FromMinutes(10)); } stopwatch.Stop(); txtResult.Text = string.Empty; txtResult.Text += "Cache Write (" + loop.ToString() + ") took: " + stopwatch.ElapsedMilliseconds.ToString() + " milliseconds." + Environment.NewLine; txtResult.Text += "Cache Write (" + loop.ToString() + ") took: " + (stopwatch.ElapsedMilliseconds / 1000).ToString() + " seconds." + Environment.NewLine; }
private void cacheRead_Click(object sender, EventArgs e) { int loop = Int32.Parse(txtLoop.Text); Interface.Repository.ICacheRepository cacheManager = DI.Container.Resolve <Interface.Repository.ICacheRepository>(); string cacheKey = largeObjectModel.LargeObjectId.ToString(); Model.LargeObject.LargeObjectModel loadedModel = null; System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); for (int i = 1; i <= loop; i++) { cacheKey = i.ToString(); loadedModel = cacheManager.Get <Model.LargeObject.LargeObjectModel>(cacheKey); } stopwatch.Stop(); txtResult.Text = string.Empty; txtResult.Text += "Cache Read (" + loop.ToString() + ") took: " + stopwatch.ElapsedMilliseconds.ToString() + " milliseconds." + Environment.NewLine; txtResult.Text += "Cache Read (" + loop.ToString() + ") took: " + (stopwatch.ElapsedMilliseconds / 1000).ToString() + " seconds." + Environment.NewLine; }