private async Task <IEnumerable <ProfileResult> > LoadResults(CancellationToken cancellationToken) { var cachedResults = _profileCache.GetProfileResults(); if (cachedResults != null) { return(cachedResults); } var storeResults = (await _profileStore.GetProfileResults(cancellationToken).ConfigureAwait(false)).ToList(); _profileCache.StoreProfileResults(storeResults); return(storeResults); }
private void UpdateResultsCache(Profile profile) { // We need to update cache information for the publicly visible profiles var results = _cache.GetProfileResults(); if (results == null) { // There are no results in the cache so we don't need to update it return; } var cachedResult = results.FirstOrDefault(x => x.Id == profile.Id); var cacheRequiresUpdate = false; if (cachedResult != null) { // We found this profile in the cache, the profile has been updated, has been deleted // or is hidden or banned We need to start by removing the existing profile from the cache results.Remove(cachedResult); cacheRequiresUpdate = true; } if (profile.Status != ProfileStatus.Hidden && profile.BannedAt == null) { // The profile is visible so the updated profile needs to be added into the results cache var newResult = new ProfileResult(profile); results.Add(newResult); cacheRequiresUpdate = true; } if (cacheRequiresUpdate) { _cache.StoreProfileResults(results); } }