mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2024-11-13 00:54:20 +01:00
26 lines
831 B
C#
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;
|
|
|
|
}
|
|
} |