public static string C_GETtDBCheckStock(string ptPlantCode) { StringBuilder oSql = new StringBuilder(); try { var tPath = "~/Config/DBStock.json"; var oDBStk = new mlDBStk(); oDBStk = JsonConvert.DeserializeObject <mlDBStk>(File.ReadAllText(HttpContext.Current.Server.MapPath(tPath))); //Memcach init var oMC_Usr = new BaseCacheManager <mlDBStk>(cCNVB.oCMConfig); oMC_Usr.AddOrUpdate("key", oDBStk, _ => oDBStk); oDBStk = oMC_Usr.Get("key"); //Select DB form Brance json var aDB = (from oResultDBStk in oDBStk.DatabaseStock where oResultDBStk.Brance == ptPlantCode.Substring(2, 2) select oResultDBStk).ToList(); oSql.AppendLine("Data Source = " + aDB[0].ServerName + " "); oSql.AppendLine(";Initial Catalog = " + aDB[0].DabaseName + " "); oSql.AppendLine(";Persist Security Info=True;User ID =" + aDB[0].User + " "); oSql.AppendLine(";Password = "******" "); oSql.AppendLine(";Connection Timeout=15;Connection Lifetime=0;Min Pool Size=0;Max Pool Size=30;Pooling=true"); return(oSql.ToString()); } catch (Exception oEx) { throw oEx; } }
public Task <PlayerModel> Get(string key) { try { return(Task.FromResult(_playersCacheManager.Get <PlayerModel>(key))); } catch (Exception ex) { _logger.LogError(ex, ex.ToString()); } return(null); }
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { var result = _cache.Get(KeyPrefix); if (result != null) { return(input.CreateMethodReturn(result)); } IMethodReturn methodReturn = getNext()(input, getNext); _cache.Add(KeyPrefix, methodReturn.ReturnValue); return(methodReturn); }
public async Task Events_OnRemoveExternal_Redis_NoneHandling() { var client = ConnectionMultiplexer.Connect("localhost"); var config = new ConfigurationBuilder() .WithUpdateMode(CacheUpdateMode.None) .WithDictionaryHandle() .And .WithJsonSerializer() .WithRedisConfiguration("redis", client, enableKeyspaceNotifications: true) .WithRedisCacheHandle("redis") .Build(); var key = Guid.NewGuid().ToString(); var onRemoveByHandleValid = false; var onRemoveValid = false; var cache = new BaseCacheManager <int?>(config); cache.OnRemoveByHandle += (s, args) => { if (args.Reason == CacheItemRemovedReason.ExternalDelete && args.Key == key) { onRemoveByHandleValid = true; } }; cache.OnRemove += (s, args) => { if (args.Key == key) { onRemoveValid = true; } }; cache.Add(key, 1234).Should().BeTrue(); var x = cache.Get(key); client.GetDatabase(0).KeyDelete(key); await Task.Delay(1000); onRemoveByHandleValid.Should().BeTrue("onRemoveByHandle Event should have been raised"); onRemoveValid.Should().BeTrue("onRemove Event should have been raised"); cache.CacheHandles.First().Get(key).Should().Be(1234); }
public async Task <CacheItemRemovedEventArgs> RunTest(ICacheManagerConfiguration configuration, string useKey, string useRegion, bool endGetShouldBeNull = true, bool runGetWhileWaiting = true) { var triggered = false; CacheItemRemovedEventArgs resultArgs = null; var cache = new BaseCacheManager <string>(configuration); cache.OnRemoveByHandle += (sender, args) => { triggered = true; resultArgs = args; }; if (useRegion == null) { cache.Add(useKey, "value"); cache.Get(useKey).Should().NotBeNull(); } else { cache.Add(useKey, "value", useRegion); cache.Get(useKey, useRegion).Should().NotBeNull(); } // sys runtime checks roughly every 10 seconds, there is no other way to test this quicker I think var count = 0; while (count < 30 && !triggered) { if (runGetWhileWaiting) { if (useRegion == null) { cache.CacheHandles.ToList().ForEach(p => p.Get(useKey)); } else { cache.CacheHandles.ToList().ForEach(p => p.Get(useKey, useRegion)); } } await Task.Delay(1000); count++; } if (!triggered) { throw new Exception("Waited pretty long, no events triggered..."); } // validate on Up update mode, the handles above have been cleaned up for example if (endGetShouldBeNull) { if (useRegion == null) { cache.Get(useKey).Should().BeNull(); } else { cache.Get(useKey, useRegion).Should().BeNull(); } } return(resultArgs); }