mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
merge and small changes
This commit is contained in:
commit
83bbd3fd88
6 changed files with 44 additions and 12 deletions
|
@ -28,6 +28,11 @@ namespace PlexRequests.Core
|
|||
{
|
||||
public class CacheKeys
|
||||
{
|
||||
public struct TimeFrameMinutes
|
||||
{
|
||||
public const int SchedulerCaching = 60;
|
||||
}
|
||||
|
||||
public const string PlexLibaries = "PlexLibaries";
|
||||
|
||||
public const string TvDbToken = "TheTvDbApiToken";
|
||||
|
|
|
@ -73,8 +73,8 @@ namespace PlexRequests.Helpers
|
|||
/// <returns></returns>
|
||||
public T Get<T>(string key) where T : class
|
||||
{
|
||||
var item = Cache.Get(key) as T;
|
||||
return item;
|
||||
lock (key)
|
||||
return Cache.Get(key) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -86,7 +86,11 @@ namespace PlexRequests.Helpers
|
|||
public void Set(string key, object data, int cacheTime = 20)
|
||||
{
|
||||
var policy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now + TimeSpan.FromMinutes(cacheTime) };
|
||||
Cache.Add(new CacheItem(key, data), policy);
|
||||
lock (key)
|
||||
{
|
||||
Cache.Remove(key);
|
||||
Cache.Add(new CacheItem(key, data), policy);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -98,7 +102,10 @@ namespace PlexRequests.Helpers
|
|||
var keys = Cache.Where(x => x.Key.Contains(key));
|
||||
foreach (var k in keys)
|
||||
{
|
||||
Cache.Remove(k.Key);
|
||||
lock (key)
|
||||
{
|
||||
Cache.Remove(k.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,10 @@ namespace PlexRequests.Services.Jobs
|
|||
{
|
||||
Log.Trace("Getting all movies from CouchPotato");
|
||||
var movies = CpApi.GetMovies(settings.FullUri, settings.ApiKey, new[] { "active" });
|
||||
Cache.Set(CacheKeys.CouchPotatoQueued, movies, 10);
|
||||
if (movies != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.CouchPotatoQueued, movies, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
private List<PlexSearch> CachedLibraries(AuthenticationSettings authSettings, PlexSettings plexSettings, bool setCache)
|
||||
{
|
||||
Log.Trace("Obtaining library sections from Plex for the following request");
|
||||
Log.Trace("Obtaining library sections from Plex");
|
||||
|
||||
List<PlexSearch> results = new List<PlexSearch>();
|
||||
|
||||
|
@ -250,12 +250,22 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
if (setCache)
|
||||
{
|
||||
results = GetLibraries(authSettings, plexSettings);
|
||||
Cache.Set(CacheKeys.PlexLibaries, results, 10);
|
||||
Log.Trace("Plex Lib API Call");
|
||||
results = GetLibraries(authSettings, plexSettings);
|
||||
|
||||
Log.Trace("Plex Lib Cache Set Call");
|
||||
if (results != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.PlexLibaries, results, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
results = Cache.GetOrSet(CacheKeys.PlexLibaries, () => GetLibraries(authSettings, plexSettings), 10);
|
||||
Log.Trace("Plex Lib GetSet Call");
|
||||
results = Cache.GetOrSet(CacheKeys.PlexLibaries, () => {
|
||||
Log.Trace("Plex Lib API Call (inside getset)");
|
||||
return GetLibraries(authSettings, plexSettings);
|
||||
}, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -278,6 +288,7 @@ namespace PlexRequests.Services.Jobs
|
|||
}
|
||||
}
|
||||
|
||||
Log.Trace("Returning Plex Libs");
|
||||
return libs;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,11 @@ namespace PlexRequests.Services.Jobs
|
|||
if (settings.Enabled)
|
||||
{
|
||||
Log.Trace("Getting all shows from SickRage");
|
||||
var movies = SrApi.GetShows(settings.ApiKey, settings.FullUri);
|
||||
Cache.Set(CacheKeys.SickRageQueued, movies.Result);
|
||||
var shows = SrApi.GetShows(settings.ApiKey, settings.FullUri);
|
||||
if (shows != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.SickRageQueued, shows.Result, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,10 @@ namespace PlexRequests.Services.Jobs
|
|||
{
|
||||
Log.Trace("Getting all tv series from Sonarr");
|
||||
var series = SonarrApi.GetSeries(settings.ApiKey, settings.FullUri);
|
||||
Cache.Set(CacheKeys.SonarrQueued, series, 10);
|
||||
if (series != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.SonarrQueued, series, CacheKeys.TimeFrameMinutes.SchedulerCaching);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue