Exemplo n.º 1
0
        public void Invalidation_messages_call_Invalidate_on_inner_cache()
        {
            // Arrange
            string?invalidatedKey = null;
            var    innerCache     = new InspectableCache(key => { invalidatedKey = key; });

            var subscriber = FakeRedis.CreateSubscriber();

            var sut = new RedisInvalidationReceiver(innerCache, subscriber, "invalidation");

            // Act
            subscriber.Publish("invalidation", "testKey");

            // Assert
            Assert.Equal("testKey", invalidatedKey);
        }
        public async Task InvalidateAsync_when_l2_called_then_l1_not_called_yet()
        {
            // Arrange
            var l1     = false;
            var l2     = false;
            var level1 = new InspectableCache((key) => { l1 = true; });
            var level2 = new InspectableCache((key) => { l2 = true; });

            var sut = new CompositeCache(level1, level2);

            // Act
            await sut.InvalidateAsync("a");

            // Assert
            Assert.True(l1);
            Assert.True(l2);
        }
        public async Task InvalidateAsync_when_called_l1_and_l2_called()
        {
            // Arrange
            var l1First = false;
            var l2First = false;
            var level1  = new InspectableCache((key) => { l1First = !l2First; });
            var level2  = new InspectableCache((key) => { l2First = !l1First; });

            var sut = new CompositeCache(level1, level2);

            // Act
            await sut.InvalidateAsync("a");

            // Assert
            Assert.True(l2First);
            Assert.False(l1First);
        }
        public void GetSet_when_l1_misses_then_l2_called()
        {
            // Arrange
            var l1     = false;
            var l2     = false;
            var level1 = new InspectableCache((key) => { l1 = true; }, cacheMiss: true);
            var level2 = new InspectableCache((key) => { l2 = true; });

            var sut = new CompositeCache(level1, level2);

            // Act
            var result = sut.GetSet("a", () => "", TimeSpan.Zero);

            // Assert
            Assert.True(l1);
            Assert.True(l2);
        }