SharpRSS/SharpRss/Core/FeedCache.cs
2023-06-16 22:53:26 +02:00

26 lines
831 B
C#

using System.Collections.Generic;
using System.Linq;
using SharpRss.Models;
using SharpRss.Services;
namespace SharpRss.Core
{
public class FeedCache
{
public FeedCache()
{
FetchFeeds();
}
private readonly SyndicationService _syndicationService = new SyndicationService();
private Dictionary<string, SyndicationModel> _cachedFeeds = new Dictionary<string, SyndicationModel>();
private async void FetchFeeds()
{
HashSet<SyndicationModel> fetchedFeeds = await _syndicationService.GetFeedsAsync();
_cachedFeeds = fetchedFeeds.ToDictionary(x => x.EncodedUrl);
}
public SyndicationModel? CacheFeed(string encodedUrl) => _cachedFeeds.TryGetValue(encodedUrl, out SyndicationModel model) ? model : null;
}
}