1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 17:59:14 +00:00

Added caching to SAB

This commit is contained in:
Mark McDowall 2013-09-06 17:45:13 -07:00
parent 739188a577
commit 1454f158f5
2 changed files with 27 additions and 18 deletions

View file

@ -18,7 +18,6 @@ public class SceneMappingService : ISceneMappingService,
IHandleAsync<ApplicationStartedEvent>,
IExecute<UpdateSceneMappingCommand>
{
private readonly ISceneMappingRepository _repository;
private readonly ISceneMappingProxy _sceneMappingProxy;
private readonly Logger _logger;

View file

@ -6,6 +6,7 @@
using Newtonsoft.Json.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Cache;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser.Model;
using RestSharp;
@ -53,12 +54,14 @@ public class SabnzbdClient : IDownloadClient
{
private readonly IConfigService _configService;
private readonly IHttpProvider _httpProvider;
private readonly ICached<IEnumerable<QueueItem>> _queueCache;
private readonly Logger _logger;
public SabnzbdClient(IConfigService configService, IHttpProvider httpProvider, Logger logger)
public SabnzbdClient(IConfigService configService, IHttpProvider httpProvider, ICacheManger cacheManger, Logger logger)
{
_configService = configService;
_httpProvider = httpProvider;
_queueCache = cacheManger.GetCache<IEnumerable<QueueItem>>(GetType(), "queue");
_logger = logger;
}
@ -96,6 +99,8 @@ public bool IsConfigured
}
public IEnumerable<QueueItem> GetQueue()
{
return _queueCache.Get("queue", () =>
{
string action = String.Format("mode=queue&output=json&start={0}&limit={1}", 0, 0);
string request = GetSabRequest(action);
@ -105,6 +110,8 @@ public IEnumerable<QueueItem> GetQueue()
var sabQueue = JsonConvert.DeserializeObject<SabQueue>(JObject.Parse(response).SelectToken("queue").ToString()).Items;
var queueItems = new List<QueueItem>();
foreach (var sabQueueItem in sabQueue)
{
var queueItem = new QueueItem();
@ -113,8 +120,11 @@ public IEnumerable<QueueItem> GetQueue()
queueItem.Size = sabQueueItem.Size;
queueItem.SizeLeft = sabQueueItem.Size;
yield return queueItem;
queueItems.Add( queueItem);
}
return queueItems;
}, TimeSpan.FromSeconds(10));
}
public virtual List<SabHistoryItem> GetHistory(int start = 0, int limit = 0)