コード例 #1
0
        public void RemoveByTag_ManyItemSingleTag_ReturnsNoValues()
        {
            var redis = new RedisConnectionManager();
            var cache = new RedisCacheProvider(redis);

            cache.Logger = new TestRedisLogger();
            string   key1    = "TagCacheTests:Add1";
            string   key2    = "TagCacheTests:Add2";
            string   key3    = "TagCacheTests:Add3";
            String   value1  = "Hello World!";
            String   value3  = "Two";
            String   value2  = "Three";
            DateTime expires = new DateTime(2099, 12, 11);
            var      tags    = new List <string> {
                "another tag"
            };

            cache.Set(key1, value1, expires, tags);
            cache.Set(key2, value2, expires, tags);
            cache.Set(key3, value3, expires, tags);

            var results = cache.GetByTag <String>(tags[0]);

            Assert.IsNotNull(results);
            Assert.AreEqual(results.Count, 3);


            cache.RemoveByTag(tags[0]);
            results = cache.GetByTag <String>(tags[0]);

            Assert.IsNull(results);
        }
コード例 #2
0
        public async Task ShouldRemoveAllItemsByTag()
        {
            // Arrange
            var cache = new RedisCacheProvider(_redis)
            {
                Logger = new TestRedisLogger()
            };
            var          key1   = _fixture.FormatKey($"{Guid.NewGuid()}TagCacheTests:Add1");
            var          key2   = _fixture.FormatKey($"{Guid.NewGuid()}TagCacheTests:Add2");
            var          key3   = _fixture.FormatKey($"{Guid.NewGuid()}TagCacheTests:Add3");
            const string value1 = "Test Value 1";
            const string value2 = "Test Value 2";
            const string value3 = "Test Value 3";
            var          tag    = $"{Guid.NewGuid()}_tag";
            var          expiry = DateTime.Now.AddSeconds(30);

            await Task.WhenAll(cache.SetItem(key1, value1, expiry, tag), cache.SetItem(key2, value2, expiry, tag),
                               cache.SetItem(key3, value3, expiry, tag)).ConfigureAwait(false);

            // Act
            var result = (await cache.GetByTag <string>(tag).ConfigureAwait(false)).ToArray();

            result.ShouldNotBeNull();
            result.ShouldNotBeEmpty();

            await cache.RemoveByTag(tag).ConfigureAwait(false);

            result = (await cache.GetByTag <string>(tag).ConfigureAwait(false)).ToArray();

            // Assert
            result.ShouldBeEmpty();
        }
コード例 #3
0
        public void RemoveByTag_ManyItemSingleTag_ReturnsNoValues()
        {
            var redis = new RedisConnectionManager();
            var cache = new RedisCacheProvider(redis);
            cache.Logger = new TestRedisLogger();
            string key1 = "TagCacheTests:Add1";
            string key2 = "TagCacheTests:Add2";
            string key3 = "TagCacheTests:Add3";
            String value1 = "Hello World!";
            String value3 = "Two";
            String value2 = "Three";
            DateTime expires = new DateTime(2099, 12, 11);
            var tags = new List<string> { "another tag" };

            cache.Set(key1, value1, expires, tags);
            cache.Set(key2, value2, expires, tags);
            cache.Set(key3, value3, expires, tags);

            var results = cache.GetByTag<String>(tags[0]);

            Assert.IsNotNull(results);
            Assert.AreEqual(results.Count, 3);


            cache.RemoveByTag(tags[0]);
            results = cache.GetByTag<String>(tags[0]);

            Assert.IsNull(results);
        }