SharpRSS/SharpRss/Core/FeedCache.cs

26 lines
831 B
C#
Raw Normal View History

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();
2023-06-16 22:53:26 +02:00
private Dictionary<string, SyndicationModel> _cachedFeeds = new Dictionary<string, SyndicationModel>();
private async void FetchFeeds()
{
2023-06-16 22:53:26 +02:00
HashSet<SyndicationModel> fetchedFeeds = await _syndicationService.GetFeedsAsync();
_cachedFeeds = fetchedFeeds.ToDictionary(x => x.EncodedUrl);
}
2023-06-16 22:53:26 +02:00
public SyndicationModel? CacheFeed(string encodedUrl) => _cachedFeeds.TryGetValue(encodedUrl, out SyndicationModel model) ? model : null;
}
}