Exemplo n.º 1
0
        public void Get()
        {
            var         factory = new FoobarCacheFactory().Register("foobar", new CacheEntryOptions());
            FoobarCache cache1  = (FoobarCache)factory.Get("Foobar");
            FoobarCache cache2  = (FoobarCache)factory.Get("foobar");

            Assert.Same(cache1, cache2);
        }
Exemplo n.º 2
0
        public async void Get_Clear_On_Change()
        {
            _source = new CancellationTokenSource();
            Func <IChangeToken> changeTokenAccessor = () => _source.IsCancellationRequested ?
                                                      new CancellationChangeToken((_source = new CancellationTokenSource()).Token)
        : new CancellationChangeToken(_source.Token);
            var factory = new FoobarCacheFactory().Register("foobar", new CacheEntryOptions {
                ExpirationTokenAccessor = changeTokenAccessor
            });
            var cache = factory.Get("foobar");

            _source.Cancel();
            await Task.Delay(100);

            Assert.NotNull(_expirationIndicator);

            _expirationIndicator = null;
            _source.Cancel();
            await Task.Delay(100);

            Assert.NotNull(_expirationIndicator);
        }