public static IEnumerable <string> GetUniqueValues(MediaType mediaType, string fieldName) { string key = GetFilterKey(mediaType, fieldName); if (UniqueValuesCache.ContainsKey(key)) { return(UniqueValuesCache[key]); } IEnumerable <string> enumerable = fieldName == "Item.GenreIds" ? GetEnumerable(mediaType, fieldName)?.OrderBy(x => x) : GetEnumerable(mediaType, fieldName)?.SelectMany(x => x.SplitByListSeparator()).Distinct().OrderBy(x => x); if (enumerable != null) { UniqueValuesCache.Add(key, enumerable); IDictionary <string, object> uniqueValues = UniqueValues as IDictionary <string, object>; uniqueValues[key] = enumerable; } return(enumerable); }
static FilterHelper() { Messenger.Default.Register(listener, (CultureChangeMessage message) => { UniqueValuesCache.Remove("Movie_GenreIds"); UniqueValuesCache.Remove("Tv_GenreIds"); PredefinedFilterCache.Remove("Movie_GenreIds"); PredefinedFilterCache.Remove("Tv_GenreIds"); }); App.Repository.Movies.CollectionChanged += (s, e) => { if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.Remove) { List <string> expiredKeys = PredefinedFilterCache.Keys.Where(x => x.StartsWith("Movie_") && !x.EndsWith("GenreIds")).ToList(); foreach (string key in expiredKeys) { UniqueValuesCache.Remove(key); PredefinedFilterCache.Remove(key); } } }; App.Repository.TvShows.CollectionChanged += (s, e) => { if (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.Remove) { List <string> expiredKeys = PredefinedFilterCache.Keys.Where(x => x.StartsWith("Tv_") && !x.EndsWith("GenreIds")).ToList(); foreach (string key in expiredKeys) { UniqueValuesCache.Remove(key); PredefinedFilterCache.Remove(key); } } }; }