public void CacheKey_get_success() { var lookup = new CacheLookup <CacheItem>() .Add(x => x.LookupKey); var key = lookup.CacheKey; Assert.That(key, Is.EqualTo("Lookup_CacheItem_LookupKey")); }
public void GetLookupKey_sucess() { var lookup = new CacheLookup <CacheItem>() .Add(x => x.LookupKey) .Add(x => x.LookupKeyOther); var key = lookup.GetLookupKey(new CacheItem { LookupKey = 1, LookupKeyOther = "other" }); Assert.That(key, Is.EqualTo("1_other")); }
public async Task FetchAsync_lookup_test() { var root = Substitute.For <ISite>(); var cacheRegistry = new CacheRegistry(new TestCacheConfig()); var cacheStore = new CacheStore(); var lookup = new CacheLookup <CacheItem>().Add(x => x.LookupKey); var lookupOther = new CacheLookup <CacheItem>().Add(x => x.LookupKeyOther); var cache = new Cache(cacheStore, cacheRegistry, root); async Task <IEnumerable <CacheItem> > Task(ICache c) => await System.Threading.Tasks.Task.Run(() => new[] { new CacheItem { LookupKey = 1, LookupKeyOther = "2" }, new CacheItem { LookupKey = 1, LookupKeyOther = "2" }, new CacheItem { LookupKey = 2, LookupKeyOther = "1" } }).ConfigureAwait(false); cacheRegistry.Add(Task).Lookup(lookup).Lookup(lookupOther).Span(300); var result = await cache.FetchAsync(lookup).ConfigureAwait(false); var resultOther = await cache.FetchAsync(lookupOther).ConfigureAwait(false); var item = result["2"].First(); var itemOther = resultOther["1"].First(); Assert.That(result, Is.Not.Null); Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result["1"].Count(), Is.EqualTo(2)); Assert.That(result["2"].Count(), Is.EqualTo(1)); Assert.That(resultOther, Is.Not.Null); Assert.That(resultOther.Count, Is.EqualTo(2)); Assert.That(resultOther["1"].Count(), Is.EqualTo(1)); Assert.That(resultOther["2"].Count(), Is.EqualTo(2)); Assert.That(item.Id, Is.EqualTo(itemOther.Id)); }
public async Task Run_with_lookups_concurrent_run_single_result_success() { const int cacheTime = 300; var cache = Substitute.For <ICache>(); var items = new Dictionary <string, object>(); var taskKey = typeof(CacheItem).FullName; var lookup = new CacheLookup <CacheItem>().Add(x => x.LookupKey); var task = new CacheTask <CacheItem>(_task, taskKey).Span(cacheTime); task.Lookup(lookup); void Save(string key, object value) { items[key] = value; } await task.Run(cache, Save).ConfigureAwait(false); var lookups = items["Lookup_CacheItem_LookupKey"] as ILookup <string, CacheItem>; var all = items[taskKey] as IEnumerable <CacheItem>; Assert.That(items.Count, Is.EqualTo(2)); Assert.That(all.Count(), Is.EqualTo(3)); Assert.That(lookups.Count(), Is.EqualTo(2)); var lookupKey1 = lookup.GetLookupKey(new CacheItem { LookupKey = 1 }); var lookupKey2 = lookup.GetLookupKey(new CacheItem { LookupKey = 2 }); Assert.That(lookups[lookupKey1].Count(), Is.EqualTo(2)); Assert.That(lookups[lookupKey2].Count(), Is.EqualTo(1)); }
public override int GetHashCode() { int hash = 1; if (RequestMethod.Length != 0) { hash ^= RequestMethod.GetHashCode(); } if (RequestUrl.Length != 0) { hash ^= RequestUrl.GetHashCode(); } if (RequestSize != 0L) { hash ^= RequestSize.GetHashCode(); } if (Status != 0) { hash ^= Status.GetHashCode(); } if (ResponseSize != 0L) { hash ^= ResponseSize.GetHashCode(); } if (UserAgent.Length != 0) { hash ^= UserAgent.GetHashCode(); } if (RemoteIp.Length != 0) { hash ^= RemoteIp.GetHashCode(); } if (ServerIp.Length != 0) { hash ^= ServerIp.GetHashCode(); } if (Referer.Length != 0) { hash ^= Referer.GetHashCode(); } if (latency_ != null) { hash ^= Latency.GetHashCode(); } if (CacheLookup != false) { hash ^= CacheLookup.GetHashCode(); } if (CacheHit != false) { hash ^= CacheHit.GetHashCode(); } if (CacheValidatedWithOriginServer != false) { hash ^= CacheValidatedWithOriginServer.GetHashCode(); } if (CacheFillBytes != 0L) { hash ^= CacheFillBytes.GetHashCode(); } return(hash); }