2023-06-15 20:04:15 +02:00
|
|
|
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>();
|
2023-06-15 20:04:15 +02:00
|
|
|
|
|
|
|
private async void FetchFeeds()
|
|
|
|
{
|
2023-06-16 22:53:26 +02:00
|
|
|
HashSet<SyndicationModel> fetchedFeeds = await _syndicationService.GetFeedsAsync();
|
2023-06-15 20:04:15 +02:00
|
|
|
_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;
|
2023-06-15 20:04:15 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|