SharpRSS/SharpRss/Core/FeedCache.cs

26 lines
796 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, FeedModel> _cachedFeeds = new Dictionary<string, FeedModel>();
private async void FetchFeeds()
{
HashSet<FeedModel> fetchedFeeds = await _syndicationService.GetFeedsAsync();
_cachedFeeds = fetchedFeeds.ToDictionary(x => x.EncodedUrl);
}
public FeedModel? CacheFeed(string encodedUrl) => _cachedFeeds.TryGetValue(encodedUrl, out FeedModel model) ? model : null;
}
}