public void ShouldExpireAsPerPolicy() { var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(5), RegionName); var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0); sut.Add("bob", result); Thread.Sleep(TimeSpan.FromSeconds(8)); var cached = sut.Get("bob", 1); Assert.IsNull(cached); }
public void ShouldClearRegionOnCallingClear() { var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(150), RegionName); var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0); sut.Add("bob", result); sut.Clear(); var cached = sut.Get("bob", 1); Assert.IsNull(cached); }
public void ShouldNotExpireIfPolicySaysInfinite() { var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(ObjectCache.InfiniteAbsoluteExpiration.Second), RegionName); var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0); sut.Add("bob", result); Thread.Sleep(TimeSpan.FromSeconds(10)); var cached = sut.Get("bob", 1); Assert.IsNotNull(cached); }
public void Add(string cacheKey, SearchResult cacheItem) { try { this.DataCache.Add(cacheKey, cacheItem, this.DetermineTimeOut(), this.CacheRegionName); } catch (DataCacheException e) { // swallow this for now, to stay consistent with how the local MemoryCache was working // could look at using Put instead to add or replace if (e.ErrorCode != DataCacheErrorCode.KeyAlreadyExists) { throw; } } }
public void ShouldSwallowKeyAlreadyExists() { var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(15), RegionName); var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0); sut.Add("bob", result); sut.Add("bob", result); // would throw DataCacheException(KeyAlreadyExists) usually Assert.IsTrue(true); }
public void Add(string cacheKey, SearchResult cacheItem) { this.cache.Add(cacheKey, cacheItem, this.cacheItemPolicyFactory.CreatePolicy()); }