Added caching all over the new API's this will help with the API limits that we will now easily reach due to the infinate scroll

This commit is contained in:
Jamie Rees 2019-05-07 13:34:39 +01:00
commit 08abb53923
5 changed files with 40 additions and 21 deletions

View file

@ -1,4 +1,5 @@
using AutoMapper;
using System;
using AutoMapper;
using System.Collections.Generic;
using System.Linq;
@ -50,8 +51,10 @@ namespace Ombi.Core.Engine.V2
public async Task<SearchFullInfoTvShowViewModel> GetShowInformation(int tvdbid)
{
var tvdbshow = await TvMazeApi.ShowLookupByTheTvDbId(tvdbid);
var show = await TvMazeApi.GetTvFullInformation(tvdbshow.id);
var tvdbshow = await Cache.GetOrAdd(nameof(GetShowInformation) + tvdbid,
async () => await TvMazeApi.ShowLookupByTheTvDbId(tvdbid), DateTime.Now.AddHours(12));
var show = await Cache.GetOrAdd("GetTvFullInformation" + tvdbshow.id,
async () => await TvMazeApi.GetTvFullInformation(tvdbshow.id), DateTime.Now.AddHours(12));
if (show == null)
{
// We don't have enough information
@ -62,7 +65,8 @@ namespace Ombi.Core.Engine.V2
Task<TraktShow> traktInfoTask = new Task<TraktShow>(() => null);
if (show.externals?.imdb.HasValue() ?? false)
{
traktInfoTask = TraktApi.GetTvExtendedInfo(show.externals?.imdb);
traktInfoTask = Cache.GetOrAdd("GetExtendedTvInfoTrakt" + show.externals?.imdb,
() => TraktApi.GetTvExtendedInfo(show.externals?.imdb), DateTime.Now.AddHours(12));
}
var mapped = Mapper.Map<SearchFullInfoTvShowViewModel>(show);