mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
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:
parent
8de5057fd3
commit
189cfcaf05
28 changed files with 392 additions and 38 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue