public async Task <IEnumerable <T> > LoadAsync(TKey key) { lock (_cache) { // Get value from the cache if it's there if (_cache.TryGetValue(key, out var value)) { return(value); } // Otherwise add to pending keys if (!_pendingKeys.Contains(key)) { _pendingKeys.Add(key); } } var result = await DataLoaded.ConfigureAwait(false); var rv = result[key]; if (rv == null) { lock (_cache) { _cache.TryGetValue(key, out rv); } } return(rv); }
public async Task <T> LoadAsync(TKey key) { lock (_cache) { // Get value from the cache if it's there if (_cache.TryGetValue(key, out T cacheValue)) { return(cacheValue); } // Otherwise add to pending keys if (!_pendingKeys.Contains(key)) { _pendingKeys.Add(key); } } var result = await DataLoaded.ConfigureAwait(false); if (result.TryGetValue(key, out T value)) { return(value); } else { return(_defaultValue); } }
public async Task <Connection <T> > LoadPageAsync(PageRequest <TKey> pageRequest) { lock (_pendingRequests) { _pendingRequests.Add(pageRequest); } var result = await DataLoaded.ConfigureAwait(false); return(result.TryGetValue(pageRequest.Key, out var value) ? value : default);