work on issues and imporving the api.

Also added the GroupMe Api project so we can later add this as another notification agent
This commit is contained in:
Jamie Rees 2019-05-31 14:54:51 +01:00
commit 189cfcaf05
28 changed files with 392 additions and 38 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Nito.AsyncEx;
@ -16,7 +17,7 @@ namespace Ombi.Helpers
_memoryCache = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));
}
public async Task<T> GetOrAdd<T>(string cacheKey, Func<Task<T>> factory, DateTime absoluteExpiration = default(DateTime))
public async Task<T> GetOrAdd<T>(string cacheKey, Func<Task<T>> factory, DateTime absoluteExpiration = default(DateTime), CancellationToken cancellationToken = default(CancellationToken))
{
if (absoluteExpiration == default(DateTime))
{
@ -33,6 +34,11 @@ namespace Ombi.Helpers
return result;
}
if (cancellationToken.CanBeCanceled)
{
cancellationToken.ThrowIfCancellationRequested();
}
result = await factory();
_memoryCache.Set(cacheKey, result, absoluteExpiration);

View file

@ -1,11 +1,12 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Ombi.Helpers
{
public interface ICacheService
{
Task<T> GetOrAdd<T>(string cacheKey, Func<Task<T>> factory, DateTime absoluteExpiration = default(DateTime));
Task<T> GetOrAdd<T>(string cacheKey, Func<Task<T>> factory, DateTime absoluteExpiration = default(DateTime), CancellationToken cancellationToken = default(CancellationToken));
T GetOrAdd<T>(string cacheKey, Func<T> factory, DateTime absoluteExpiration);
void Remove(string key);
}