using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using SharpRss.Models; namespace SharpRss.Core.Cache { internal enum CacheFetch { Category, Syndication } internal static class TempCache { private static Dictionary _categoryCache = new Dictionary(); private static Dictionary _syndicationCache = new Dictionary(); public static async Task UpdateCache(CacheFetch cf) { switch (cf) { case CacheFetch.Category: var cats = await DbAccess.GetCategoriesAsync(); _categoryCache = cats.ToDictionary(x => x.Id); break; case CacheFetch.Syndication: var syndications = await DbAccess.GetSyndicationsAsync(); _syndicationCache = syndications.ToDictionary(x => x.EncodedUrl); break; } } public static CategoryModel? GetCategory(string catId) => _categoryCache.TryGetValue(catId, out CategoryModel catModel) ? catModel : null; public static SyndicationModel? GetSyndication(string encodedUrl) => _syndicationCache.TryGetValue(encodedUrl, out SyndicationModel synModel) ? synModel : null; } }