public static void Main(string[] args) { var configBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder() .AddJsonFile("cache.json"); var configuration = configBuilder.Build(); ////var cacheCfgf = configuration.GetCacheConfigurations().First(); ////var mgr = new BaseCacheManager<string>(cacheCfgf); int iterations = int.MaxValue; try { var builder = new Core.ConfigurationBuilder("myCache"); builder.WithMicrosoftLogging(f => { f.AddConsole(LogLevel.Warning); f.AddDebug(LogLevel.Debug); }); builder.WithUpdateMode(CacheUpdateMode.Up); builder.WithRetryTimeout(1000); builder.WithMaxRetries(10); //#if NETCORE // builder.WithDictionaryHandle("dic") // .DisableStatistics(); // //Console.WriteLine("Using Dictionary cache handle"); //#else builder.WithDictionaryHandle() .DisableStatistics(); builder.WithRedisCacheHandle("redis", true) .DisableStatistics(); builder.WithRedisBackplane("redis"); builder.WithRedisConfiguration("redis", config => { config .WithAllowAdmin() .WithDatabase(0) .WithConnectionTimeout(5000) //.WithEndpoint("ubuntu-local", 7024); //.WithEndpoint("127.0.0.1", 6380) .WithEndpoint("127.0.0.1", 6379); //.WithEndpoint("192.168.178.34", 7001); }); builder.WithJsonSerializer(); Console.WriteLine("Using Redis cache handle"); //#endif var cacheA = new BaseCacheManager <object>(builder.Build()); cacheA.Clear(); for (int i = 0; i < iterations; i++) { try { Tests.PutAndMultiGetTest(cacheA); } catch (AggregateException ex) { ex.Handle((e) => { Console.WriteLine(e); return(true); }); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); Thread.Sleep(1000); } Console.WriteLine("---------------------------------------------------------"); } } catch (Exception ex) { Console.WriteLine(ex); } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("We are done..."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadKey(); }
public static void Main(string[] args) { int iterations = 10; try { var builder = new Core.ConfigurationBuilder("myCache"); builder.WithMicrosoftLogging(f => { f.AddConsole(LogLevel.Warning); f.AddDebug(LogLevel.Debug); }); builder.WithRetryTimeout(1000); builder.WithMaxRetries(10); builder.WithDictionaryHandle() .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromSeconds(20)) .DisableStatistics(); builder.WithRedisCacheHandle("redis", true) .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(60)) .DisableStatistics(); builder.WithRedisBackplane("redis"); builder.WithRedisConfiguration("redis", config => { config .WithAllowAdmin() .WithDatabase(0) .WithConnectionTimeout(5000) .WithEndpoint("127.0.0.1", 6379); }); builder.WithJsonSerializer(); var cacheA = new BaseCacheManager <object>(builder.Build()); cacheA.Clear(); for (int i = 0; i < iterations; i++) { try { Tests.PutAndMultiGetTest(cacheA); } catch (AggregateException ex) { ex.Handle((e) => { Console.WriteLine(e); return(true); }); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); Thread.Sleep(1000); } Console.WriteLine("---------------------------------------------------------"); } } catch (Exception ex) { Console.WriteLine(ex); } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("We are done..."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadKey(); }
public static void Main(string[] args) { ThreadPool.SetMinThreads(100, 100); var iterations = 100; try { var builder = new Core.ConfigurationBuilder("myCache"); builder.WithMicrosoftLogging(f => { f.AddConsole(LogLevel.Warning); ////f.AddDebug(LogLevel.Debug); }); builder .WithRetryTimeout(500) .WithMaxRetries(3); builder .WithDictionaryHandle() .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromSeconds(20)) .DisableStatistics(); builder .WithRedisCacheHandle("redis", true) .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(60)) .DisableStatistics(); builder.WithRedisBackplane("redis"); builder.WithRedisConfiguration("redis", config => { config //.UseTwemproxy() //.UseCompatibilityMode("2.4") .WithAllowAdmin() .WithDatabase(0) .WithConnectionTimeout(5000) .EnableKeyspaceEvents() .WithEndpoint("127.0.0.1", 6379); }); //builder.WithRedisConfiguration("redis", "localhost:22121"); builder.WithBondCompactBinarySerializer(); #if !NETCOREAPP //var memcachedCfg = new MemcachedClientConfiguration(); //memcachedCfg.AddServer("localhost", 11211); //builder.WithMemcachedCacheHandle(memcachedCfg); #endif var cacheA = new BaseCacheManager <string>(builder.Build()); cacheA.Clear(); for (var i = 0; i < iterations; i++) { try { Tests.PumpData(cacheA).GetAwaiter().GetResult(); break; // specified runtime (todo: rework this anyways) } catch (AggregateException ex) { ex.Handle((e) => { Console.WriteLine(e); return(true); }); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); Thread.Sleep(1000); } Console.WriteLine("---------------------------------------------------------"); } } catch (Exception ex) { Console.WriteLine(ex); } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("We are done..."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadKey(); }
public void Main(string[] args) { int iterations = int.MaxValue; try { var builder = new Core.ConfigurationBuilder("myCache"); builder.WithMicrosoftLogging(f => { // TODO: remove after logging upgrade to RC2 f.MinimumLevel = LogLevel.Debug; f.AddConsole(LogLevel.Error); // TODO: change to Debug after logging upgrade to RC2 f.AddDebug(LogLevel.Verbose); }); builder.WithUpdateMode(CacheUpdateMode.Up); builder.WithRetryTimeout(1000); builder.WithMaxRetries(10); #if DNXCORE50 builder.WithDictionaryHandle("dic") .DisableStatistics(); //Console.WriteLine("Using Dictionary cache handle"); #else builder.WithDictionaryHandle() .DisableStatistics(); builder.WithRedisCacheHandle("redis", true) .DisableStatistics(); builder.WithRedisBackPlate("redis"); builder.WithRedisConfiguration("redis", config => { config .WithAllowAdmin() .WithDatabase(0) .WithConnectionTimeout(5000) //.WithEndpoint("ubuntu-local", 7024); .WithEndpoint("127.0.0.1", 6380) .WithEndpoint("127.0.0.1", 6379); //.WithEndpoint("192.168.178.34", 7001); }); builder.WithJsonSerializer(); Console.WriteLine("Using Redis cache handle"); #endif var cacheA = new BaseCacheManager <object>(builder.Build()); cacheA.Clear(); #if !DNXCORE50 var redisHandle = cacheA.CacheHandles.Last() as Redis.RedisCacheHandle <object>; var features = redisHandle.Features; #endif for (int i = 0; i < iterations; i++) { try { Tests.PutAndMultiGetTest(cacheA); } catch (AggregateException ex) { ex.Handle((e) => { Console.WriteLine(e); return(true); }); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); Thread.Sleep(1000); } Console.WriteLine("---------------------------------------------------------"); } } catch (Exception ex) { Console.WriteLine(ex); } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("We are done..."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadKey(); }
public void Main(string[] args) { int iterations = int.MaxValue; try { var jsonConfiguration = this.Configuration.GetCacheConfiguration("cachename") .Builder .WithMicrosoftLogging(f => { // TODO: remove after logging upgrade to RC2 f.MinimumLevel = LogLevel.Debug; f.AddConsole(LogLevel.Information); // TODO: change to Debug after logging upgrade to RC2 f.AddDebug(LogLevel.Verbose); }) .Build(); var jsonCache = new BaseCacheManager <string>(jsonConfiguration); jsonCache.Put("key", "value"); var builder = new Core.ConfigurationBuilder("myCache"); builder.WithMicrosoftLogging(f => { // TODO: remove after logging upgrade to RC2 f.MinimumLevel = LogLevel.Debug; f.AddConsole(LogLevel.Information); // TODO: change to Debug after logging upgrade to RC2 f.AddDebug(LogLevel.Verbose); }); builder.WithUpdateMode(CacheUpdateMode.Up); builder.WithRetryTimeout(500); builder.WithMaxRetries(50); #if DNXCORE50 builder.WithDictionaryHandle("dic") .DisableStatistics(); //Console.WriteLine("Using Dictionary cache handle"); #else builder.WithSystemRuntimeCacheHandle() .DisableStatistics(); builder.WithRedisCacheHandle("redis", true) .DisableStatistics(); builder.WithRedisBackPlate("redis"); builder.WithRedisConfiguration("redis", config => { config .WithAllowAdmin() .WithDatabase(0) .WithConnectionTimeout(1000) .WithEndpoint("127.0.0.1", 6380) .WithEndpoint("127.0.0.1", 6379); //.WithEndpoint("192.168.178.34", 7001); }); builder.WithJsonSerializer(); Console.WriteLine("Using Redis cache handle"); #endif var cacheA = new BaseCacheManager <object>(builder.Build()); cacheA.Clear(); var manualConfig = new CacheManagerConfiguration(); manualConfig.CacheHandleConfigurations.Add(new CacheHandleConfiguration() { HandleType = typeof(Core.Internal.DictionaryCacheHandle <>) }); var cacheB = new BaseCacheManager <string>("name", manualConfig); for (int i = 0; i < iterations; i++) { try { Tests.PutAndMultiGetTest(cacheA); } catch (AggregateException ex) { ex.Handle((e) => { Console.WriteLine(e); return(true); }); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); Thread.Sleep(1000); } Console.WriteLine("---------------------------------------------------------"); } } catch (Exception ex) { Console.WriteLine(ex); } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("We are done..."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadKey(); }
public void Main(string[] args) { var swatch = Stopwatch.StartNew(); int iterations = int.MaxValue; swatch.Restart(); var cacheConfiguration = ConfigurationBuilder.BuildConfiguration(cfg => { cfg.WithUpdateMode(CacheUpdateMode.Up); cfg.WithRetryTimeout(100); cfg.WithMaxRetries(50); ////cfg.WithHandle(typeof(Core.Internal.DictionaryCacheHandle2<>)) //// .DisableStatistics(); #if DNXCORE50 cfg.WithDictionaryHandle() .DisableStatistics(); //Console.WriteLine("Using Dictionary cache handle"); #else cfg.WithDictionaryHandle() .DisableStatistics(); Console.WriteLine("Using System Runtime cache handle"); cfg.WithRedisCacheHandle("redis", true) .DisableStatistics(); cfg.WithRedisConfiguration("redis", config => { config .WithAllowAdmin() .WithDatabase(0) .WithConnectionTimeout(1000) .WithEndpoint("127.0.0.1", 6380) .WithEndpoint("127.0.0.1", 6379); ////.WithEndpoint("192.168.178.32", 6379); }); cfg.WithJsonSerializer(); Console.WriteLine("Using Redis cache handle"); #endif }); try { var cache = CacheFactory.FromConfiguration <object>(cacheConfiguration); for (int i = 0; i < iterations; i++) { try { cache.Clear(); cache.Add("key", "value", "region"); cache.Add(new CacheItem <object>("key2", "region", "value", ExpirationMode.Sliding, TimeSpan.FromMinutes(10))); cache.Add("key3", "value", "region"); var val = cache.Get("key2", "region"); cache.ClearRegion("region"); Tests.SimpleAddGetTest( CacheFactory.FromConfiguration <object>(cacheConfiguration)); ////Tests.RandomRWTest( //// CacheFactory.FromConfiguration<Item>(cacheConfiguration)); ////Tests.CacheThreadTest( //// CacheFactory.FromConfiguration<string>(cacheConfiguration), //// i + 10); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "\n" + e.StackTrace); Thread.Sleep(1000); } // Console.WriteLine(string.Format("Iterations ended after {0}ms.", swatch.ElapsedMilliseconds)); Console.WriteLine("---------------------------------------------------------"); swatch.Restart(); } } catch { throw; } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("We are done..."); Console.ReadLine(); }