Esempio n. 1
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            Core.DebugMode = false;
            Core.Log.Warning("Starting CACHE Async TEST");

            var cacheService = new TestCacheService();

            cacheService.OnStart(null);

            using (var cachePool = new CacheClientPoolAsync("Pool Test")
            {
                Serializer = GlobalSerializer, ForceAtLeastOneNetworkItemEnabled = false, WriteNetworkItemsToMemoryOnGet = true
            })
            {
                var cacheClient = await CacheClientProxy.GetClientAsync(new DefaultTransportClient("127.0.0.1", 20051, 3, GlobalSerializer)).ConfigureAwait(false);

                cachePool.Add("localhost:20051", cacheClient, StorageItemMode.ReadAndWrite);
                //cachePool.Add("memory", new LRU2QStorage(2000), StorageItemMode.ReadAndWrite);

                var res = await cachePool.GetMetaAsync("metaValue").ConfigureAwait(false);

                await cachePool.GetKeysAsync().ConfigureAwait(false);

                using (var watch = Watch.Create("GetKeysAsync"))
                {
                    for (var i = 0; i < 1000; i++)
                    {
                        await cachePool.GetKeysAsync().ConfigureAwait(false);
                    }
                    Core.Log.InfoBasic("Time Per Item: {0}ms", watch.GlobalElapsedMilliseconds / 1000);
                }

                Console.ReadLine();

                using (var watch = Watch.Create("Get And Sets"))
                {
                    for (var i = 0; i < 5000; i++)
                    {
                        var key = "test-" + (i % 500);
                        await cachePool.GetAsync(key).ConfigureAwait(false);

                        await cachePool.SetAsync(key, "bla bla bla bla bla").ConfigureAwait(false);
                    }
                    Core.Log.InfoBasic("Time Per Item: {0}ms", watch.GlobalElapsedMilliseconds / 5000);
                }
            }

            cacheService.OnStop();
            Console.ReadLine();
        }
Esempio n. 2
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            Core.DebugMode = true;
            Core.Log.Warning("Starting CACHE TEST");

            var cacheService = new TestCacheService();

            cacheService.OnStart(null);

            using (var cachePool = new CacheClientPoolAsync("Pool Test")
            {
                Serializer = GlobalSerializer
            })
            {
                var cacheClient = await CacheClientProxy.GetClientAsync(new DefaultTransportClient("127.0.0.1", 20051, 3, GlobalSerializer)).ConfigureAwait(false);

                cachePool.Add("localhost:20051", cacheClient, StorageItemMode.ReadAndWrite);

                await cachePool.SetAsync("expTest", "testData", TimeSpan.FromSeconds(20), new[] { "test" }).ConfigureAwait(false);

                Console.ReadLine();

                var asto = await cachePool.GetAsync("test").ConfigureAwait(false);

                if (asto is null)
                {
                    await cachePool.SetAsync("test", "value").ConfigureAwait(false);

                    asto = await cachePool.GetAsync("test").ConfigureAwait(false);
                }
                var guid = Guid.NewGuid();
                await cachePool.CopyAsync("test", guid.ToString("N")).ConfigureAwait(false);

                var asto2 = await cachePool.GetAsync(guid.ToString("N")).ConfigureAwait(false);

                var guid2 = Guid.NewGuid();
                await cachePool.CopyAsync("test", guid2.ToString("N")).ConfigureAwait(false);

                var asto3 = await cachePool.GetAsync(guid2.ToString("N")).ConfigureAwait(false);

                var guid3 = Guid.NewGuid();
                await cachePool.CopyAsync("test", guid3.ToString("N")).ConfigureAwait(false);

                var asto4 = await cachePool.GetAsync(guid3.ToString("N")).ConfigureAwait(false);

                Console.ReadLine();

                var tagValue1 = await cachePool.GetByTagAsync(new [] { "test" }).ConfigureAwait(false);

                await Task.Delay(600).ConfigureAwait(false);

                var tagValue2 = await cachePool.GetByTagAsync(new [] { "test" }).ConfigureAwait(false);

                await Task.Delay(600).ConfigureAwait(false);

                await cachePool.SetAsync("expTest2", "testData2", TimeSpan.FromMinutes(1), new[] { "test" }).ConfigureAwait(false);

                await Task.Delay(600).ConfigureAwait(false);

                var tagValue3 = await cachePool.GetByTagAsync(new[] { "test" }).ConfigureAwait(false);

                await Task.Delay(600).ConfigureAwait(false);

                var tagValue4 = await cachePool.SetMultiAsync(new[] { "testa", "testb" }, "Hola mundo", TimeSpan.FromSeconds(10)).ConfigureAwait(false);

                await Task.Delay(600).ConfigureAwait(false);

                var response = await cachePool.ExecuteExtensionAsync("SampleExtension", "Echo", new object[] { "value1", "value2" });

                Core.Log.Warning("Extension Response: {0}", response);
                Console.ReadLine();

                try
                {
                    for (var i = 0; i < 15; i++)
                    {
                        await cachePool.GetKeysAsync().ConfigureAwait(false);
                    }

                    Console.ReadLine();

                    for (var i = 0; i < 100; i++)
                    {
                        var key = "test-" + i;
                        await cachePool.GetAsync(key).ConfigureAwait(false);

                        await cachePool.SetAsync(key, "bla bla bla bla bla").ConfigureAwait(false);
                    }
                    Console.ReadLine();
                    for (var i = 0; i < 100; i++)
                    {
                        var key = "test-" + i;
                        await cachePool.GetAsync(key).ConfigureAwait(false);

                        await cachePool.SetAsync(key, "bla bla bla bla bla").ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    Core.Log.Write(ex);
                }
            }

            cacheService.OnStop();
        }