mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2024-11-10 07:54:20 +01:00
37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
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<string, CategoryModel> _categoryCache = new Dictionary<string, CategoryModel>();
|
|
private static Dictionary<string, SyndicationModel> _syndicationCache = new Dictionary<string, SyndicationModel>();
|
|
|
|
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;
|
|
}
|
|
} |