public async Task ClearCacheFor(Tournament tournament) { if (tournament == null) { throw new ArgumentNullException(nameof(tournament)); } var affectedTeams = tournament.Teams.Select(t => t.Team.TeamId.Value).ToList(); foreach (var teamId in affectedTeams) { var filter = _matchFilterFactory.MatchesForTeams(new List <Guid> { teamId }); var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder; _cache.Remove(cacheKey); } if (affectedTeams.Any()) { var clubs = await _clubDataSource.ReadClubs(new ClubFilter { TeamIds = affectedTeams }).ConfigureAwait(false); foreach (var club in clubs) { var filter = _matchFilterFactory.MatchesForTeams(club.Teams.Select(x => x.TeamId.Value).ToList()); var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder; _cache.Remove(cacheKey); } } if (tournament.TournamentLocation != null) { var filter = _matchFilterFactory.MatchesForMatchLocation(tournament.TournamentLocation.MatchLocationId.Value); var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder; _cache.Remove(cacheKey); } if (tournament.Seasons != null) { foreach (var season in tournament.Seasons) { var filter = _matchFilterFactory.MatchesForSeason(season.SeasonId.Value); var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder; _cache.Remove(cacheKey); } } if (tournament != null) { var filter = _matchFilterFactory.MatchesForTournament(tournament.TournamentId.Value); var cacheKey = CacheConstants.MatchListingsCacheKeyPrefix + _matchFilterSerializer.Serialize(filter.filter) + filter.sortOrder; _cache.Remove(cacheKey); } }
public async override Task <ActionResult> Index(ContentModel contentModel) { if (contentModel is null) { throw new ArgumentNullException(nameof(contentModel)); } var location = await _matchLocationDataSource.ReadMatchLocationByRoute(Request.RawUrl, false).ConfigureAwait(false); if (location == null) { return(new HttpNotFoundResult()); } else { var filter = _matchFilterFactory.MatchesForMatchLocation(location.MatchLocationId.Value); var model = new MatchLocationViewModel(contentModel.Content, Services?.UserService) { MatchLocation = location, DefaultMatchFilter = filter.filter, Matches = new MatchListingViewModel(contentModel.Content, Services?.UserService) { DateTimeFormatter = _dateFormatter }, }; model.AppliedMatchFilter = _matchFilterQueryStringParser.ParseQueryString(model.DefaultMatchFilter, HttpUtility.ParseQueryString(Request.Url.Query)); model.Matches.Matches = await _matchDataSource.ReadMatchListings(model.AppliedMatchFilter, filter.sortOrder).ConfigureAwait(false); model.IsAuthorized = _authorizationPolicy.IsAuthorized(model.MatchLocation); var userFilter = _matchFilterHumanizer.MatchingFilter(model.AppliedMatchFilter); if (!string.IsNullOrWhiteSpace(userFilter)) { model.FilterDescription = _matchFilterHumanizer.MatchesAndTournaments(model.AppliedMatchFilter) + userFilter; } model.Metadata.PageTitle = $"{_matchFilterHumanizer.MatchesAndTournaments(model.AppliedMatchFilter)} at {model.MatchLocation.NameAndLocalityOrTownIfDifferent()}{userFilter}"; model.Breadcrumbs.Add(new Breadcrumb { Name = Constants.Pages.MatchLocations, Url = new Uri(Constants.Pages.MatchLocationsUrl, UriKind.Relative) }); return(CurrentTemplate(model)); } }