Exemplo n.º 1
0
        public async Task CacheMissActionCanDenyFactoryCall()
        {
            var cache   = new AsyncCache <int, int>(x => x * x);
            var options = new CacheCallOptions <int, int>();

            options.CacheMissAction = () =>
            {
                options.DontCallFactory = true;
            };
            cache.GetValue(3, options).Should().Be(0);
            (await cache.GetValueAsync(3, options)).Should().Be(0);
        }
Exemplo n.º 2
0
        public void CanRegisterDefaultOptions()
        {
            var count   = 0;
            var cache   = new AsyncCache <int, int>(x => x * x);
            var options = new CacheCallOptions <int, int>()
            {
                CacheMissAction = () =>
                {
                    count++;
                }
            };

            cache.DefaultCacheCallOptions = options;
            cache.GetValue(3);
            count.Should().Be(1);
        }
Exemplo n.º 3
0
        public async Task CanAddOptionsToEachRequest()
        {
            var count   = 0;
            var cache   = new AsyncCache <int, int>(x => x * x);
            var options = new CacheCallOptions <int, int>
            {
                CacheMissAction = () =>
                {
                    count++;
                }
            };

            cache.GetValue(3, options);            // call should miss
            await cache.GetValueAsync(3, options); // call should hit

            count.Should().Be(1);
        }