Esempio n. 1
0
        public async Task SetAsync_RemoveAsync()
        {
            var key   = "key";
            var value = new byte[] { 0x20, 0x20, 0x20, };

            var prefixedKey = $"{RedisCacheOptions.InstanceName}{key}";

            await L1L2Cache.SetAsync(key, value);

            Assert.Equal(
                value,
                await L1L2Cache.GetAsync(key));
            Assert.Equal(
                value,
                L1Cache.Get(prefixedKey));
            Assert.Equal(
                value,
                await L2Cache.GetAsync(key));

            await L1L2Cache.RemoveAsync(key);

            Assert.Null(
                await L1L2Cache.GetAsync(key));
            Assert.Null(
                L1Cache.Get(prefixedKey));
            Assert.Null(
                await L2Cache.GetAsync(key));
        }
Esempio n. 2
0
        public void Set_Remove()
        {
            var key   = "key";
            var value = new byte[] { 0x20, 0x20, 0x20, };

            var prefixedKey = $"{RedisCacheOptions.InstanceName}{key}";

            L1L2Cache.Set(key, value);

            Assert.Equal(
                value,
                L1L2Cache.Get(key));
            Assert.Equal(
                value,
                L1Cache.Get(prefixedKey));
            Assert.Equal(
                value,
                L2Cache.Get(key));

            L1L2Cache.Remove(key);

            Assert.Null(
                L1L2Cache.Get(key));
            Assert.Null(
                L1Cache.Get(prefixedKey));
            Assert.Null(
                L2Cache.Get(key));
        }
    public async Task Performance_Test(
        int iterations)
    {
        Stopwatch.Restart();
        for (var iteration = 1; iteration <= iterations; iteration++)
        {
            await L2Cache.SetStringAsync(
                $"Performance:{iteration}",
                "Value",
                new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow =
                    TimeSpan.FromMinutes(5),
            });
        }
        Stopwatch.Stop();
        var l2SetTicks = Stopwatch.ElapsedTicks;

        Stopwatch.Restart();
        for (var iteration = 1; iteration <= iterations; iteration++)
        {
            await L1L2Cache.GetStringAsync(
                $"Performance:{iteration}");
        }
        Stopwatch.Stop();
        var l1L2GetPropagationTicks = Stopwatch.ElapsedTicks;

        Stopwatch.Restart();
        for (var iteration = 1; iteration <= iterations; iteration++)
        {
            await L1L2Cache.SetStringAsync(
                $"Performance:{iteration}",
                "Value",
                new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow =
                    TimeSpan.FromMinutes(5),
            });
        }
        Stopwatch.Stop();
        var l1L2SetTicks = Stopwatch.ElapsedTicks;

        Stopwatch.Restart();
        for (var iteration = 1; iteration <= iterations; iteration++)
        {
            await L2Cache.GetStringAsync(
                $"Performance:{iteration}");
        }
        Stopwatch.Stop();
        var l2GetTicks = Stopwatch.ElapsedTicks;

        Stopwatch.Restart();
        for (var iteration = 1; iteration <= iterations; iteration++)
        {
            await L1L2Cache.GetStringAsync(
                $"Performance:{iteration}");
        }
        Stopwatch.Stop();
        var l1L2GetTicks = Stopwatch.ElapsedTicks;

        Assert.True(
            l1L2SetTicks / l2SetTicks < 3,
            "L1L2Cache Set cannot perform significantly worse than RedisCache Set.");

        Assert.True(
            l2GetTicks / l1L2GetTicks > 100,
            "L1L2Cache Get must perform significantly better than RedisCache Get.");

        Assert.True(
            l1L2GetPropagationTicks / l2GetTicks < 3,
            "L1L2Cache Get with propagation cannot perform significantly worse than RedisCache Get.");
    }