Example #1
0
        public void AccessingLocalRedis100TimesLessThanASecond()
        {
            var c = new RedisStore(ConnectionString);

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < 100; i++)
            {
                var buffer = new byte[_r.Next(4 * 1024, 64 * 1024)];
                _r.NextBytes(buffer);
                var key  = new CacheKey(UrlStem + Guid.NewGuid().ToString(), new string[0]);
                var task = c.AddOrUpdateAsync(key,
                                              new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(buffer)
                });
                task.GetAwaiter().GetResult();
                var r = c.GetValueAsync(key).GetAwaiter().GetResult();
            }

            if (sw.ElapsedMilliseconds > 1000)
            {
                throw new Exception("Took more than 1000 ms");
            }
        }
Example #2
0
        public void TestConnectivity()
        {
            var redisStore = new RedisStore(ConnectionString);
            HttpResponseMessage responseMessage = null;

            Console.WriteLine(redisStore.GetValueAsync(new CacheKey("http://google.com", new string[0])).Result);
        }
Example #3
0
        public void IfNotThrowThenDoesNot()
        {
            var s = new RedisStore("NoneExisting", throwExceptions: false);
            var k = new CacheKey("https://google.com/", new string[0]);
            var r = new HttpResponseMessage(HttpStatusCode.Accepted);

            s.AddOrUpdateAsync(k, r).Wait();
            var r2      = s.GetValueAsync(k).Result;
            var removed = s.TryRemoveAsync(k).Result;

            Assert.Null(r2);
            Assert.False(removed);
        }
Example #4
0
        public void GetValue()
        {
            var redisStore = new RedisStore(ConnectionString);
            var client     = new HttpClient(new CachingHandler(redisStore)
            {
                InnerHandler = new HttpClientHandler()
            });

            var httpResponseMessage = client.GetAsync(CacheableResource1).Result;
            var response            = redisStore.GetValueAsync(new CacheKey(CacheableResource1, new string[0])).Result;

            Assert.NotNull(response);
        }
Example #5
0
        public void WorksWithMaxAgeZeroAndStillStoresIt()
        {
            var redisStore = new RedisStore(ConnectionString);
            var client     = new HttpClient(new CachingHandler(redisStore)
            {
                InnerHandler       = new HttpClientHandler(),
                DefaultVaryHeaders = new string[0]
            });

            var httpResponseMessage = client.GetAsync(MaxAgeZeroResource).Result;
            var key      = new CacheKey(MaxAgeZeroResource, new string[0]);
            var response = redisStore.GetValueAsync(key).Result;

            Assert.NotNull(response);
        }