//[Fact] public void ExpireTest() { var cacheManager = new CacheManager(); string key = "ExpireTest" + DateTime.Now.Ticks; var tags = new[] { "a", "b" }; var cacheKey = new CacheKey(key, tags); var value = "Test Value " + DateTime.Now; var cachePolicy = new CachePolicy(); bool result = cacheManager.Add(cacheKey, value, cachePolicy); result.Should().BeTrue(); // add second value with same tag string key2 = "ExpireTest2" + DateTime.Now.Ticks; var tags2 = new[] { "a", "c" }; var cacheKey2 = new CacheKey(key2, tags2); var value2 = "Test Value 2 " + DateTime.Now; var cachePolicy2 = new CachePolicy(); bool result2 = cacheManager.Add(cacheKey2, value2, cachePolicy2); result2.Should().BeTrue(); // add third value with same tag string key3 = "ExpireTest3" + DateTime.Now.Ticks; var tags3 = new[] { "b", "c" }; var cacheKey3 = new CacheKey(key3, tags3); var value3 = "Test Value 3 " + DateTime.Now; var cachePolicy3 = new CachePolicy(); bool result3 = cacheManager.Add(cacheKey3, value3, cachePolicy3); result3.Should().BeTrue(); var cacheTag = new CacheTag("a"); string tagKey = MemoryCacheProvider.GetTagKey(cacheTag); tagKey.Should().NotBeNullOrEmpty(); var cachedTag = cacheManager.Get<object>(tagKey); cachedTag.Should().NotBeNull(); // expire actually just changes the value for tag key cacheManager.Expire(cacheTag); // allow flush System.Threading.Thread.Sleep(500); var expiredTag = cacheManager.Get<object>(tagKey); expiredTag.Should().NotBeNull(); expiredTag.Should().NotBe(cachedTag); // items should have been removed var expiredValue = cacheManager.Get<string>(cacheKey.Key); expiredValue.Should().BeNull(); var expiredValue2 = cacheManager.Get<string>(cacheKey2.Key); expiredValue2.Should().BeNull(); var expiredValue3 = cacheManager.Get<string>(cacheKey3.Key); expiredValue3.Should().NotBeNull(); }
private void Set(string key, object value, sys.CacheItemPolicy policy) { _cache.Set(key, value, policy); }