private Task <TResource> Find(TKey key, CsDataFindOptions options) { TResource cached; if (resources.TryGetValue(key, out cached)) { return(Task.FromResult(cached)); } lock (this.inFlightLock) { Task <TResource> inFlight; if (!this.inFlight.TryGetValue(key, out inFlight)) { this.inFlight[key] = inFlight = this.adapter.Find <TKey, TResource>(key); inFlight.ContinueWith(t => { if (t.IsCompleted) { this.Inject(new[] { t.Result }, options); } lock (this.inFlightLock) { this.inFlight.Remove(key); } }); } return(inFlight); } }
Task <IEnumerable <TResource> > ICsDataResource <TKey, TResource> .FindAll <TQuery>(TQuery query, CsDataFindOptions options) { throw new NotImplementedException(); }
Task <TResource> ICsDataResource <TKey, TResource> .Find(TKey key, CsDataFindOptions options) { return(this.Find(key, options ?? CsDataFindOptions.Default)); }