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 @@ namespace NzbDrone.Core.DataAugmentation.Scene
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;
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 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
{
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 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
}
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 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
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 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
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)