mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Fixed the discord notification test issue
This commit is contained in:
parent
7119407141
commit
6327782c74
3 changed files with 24 additions and 9 deletions
|
@ -2,13 +2,14 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LazyCache;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace Ombi.Helpers
|
||||
{
|
||||
public class CacheService : ICacheService
|
||||
{
|
||||
protected readonly IAppCache _memoryCache;
|
||||
public CacheService(IAppCache memoryCache)
|
||||
protected readonly IMemoryCache _memoryCache;
|
||||
public CacheService(IMemoryCache memoryCache)
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
|
@ -20,7 +21,11 @@ namespace Ombi.Helpers
|
|||
absoluteExpiration = DateTimeOffset.Now.AddHours(1);
|
||||
}
|
||||
|
||||
return await _memoryCache.GetOrAddAsync<T>(cacheKey, () => factory(), absoluteExpiration);
|
||||
return await _memoryCache.GetOrCreateAsync<T>(cacheKey, entry =>
|
||||
{
|
||||
entry.AbsoluteExpiration = absoluteExpiration;
|
||||
return factory();
|
||||
});
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
|
@ -31,7 +36,11 @@ namespace Ombi.Helpers
|
|||
public T GetOrAdd<T>(string cacheKey, Func<T> factory, DateTimeOffset absoluteExpiration)
|
||||
{
|
||||
// locks get and set internally
|
||||
return _memoryCache.GetOrAdd<T>(cacheKey, () => factory(), absoluteExpiration);
|
||||
return _memoryCache.GetOrCreate<T>(cacheKey, entry =>
|
||||
{
|
||||
entry.AbsoluteExpiration = absoluteExpiration;
|
||||
return factory();
|
||||
});
|
||||
}
|
||||
|
||||
private static class TypeLock<T>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LazyCache;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace Ombi.Helpers
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ namespace Ombi.Helpers
|
|||
{
|
||||
private const string CacheKey = "MediaCacheServiceKeys";
|
||||
|
||||
public MediaCacheService(IAppCache memoryCache) : base(memoryCache)
|
||||
public MediaCacheService(IMemoryCache memoryCache) : base(memoryCache)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,24 +34,28 @@ namespace Ombi.Helpers
|
|||
// Not in the cache, so add this Key into our MediaServiceCache
|
||||
await UpdateLocalCache(cacheKey);
|
||||
|
||||
return await _memoryCache.GetOrAddAsync<T>(cacheKey, () => factory(), absoluteExpiration);
|
||||
return await _memoryCache.GetOrCreateAsync<T>(cacheKey, entry =>
|
||||
{
|
||||
entry.AbsoluteExpiration = absoluteExpiration;
|
||||
return factory();
|
||||
});
|
||||
}
|
||||
|
||||
private async Task UpdateLocalCache(string cacheKey)
|
||||
{
|
||||
var mediaServiceCache = await _memoryCache.GetAsync<List<string>>(CacheKey);
|
||||
var mediaServiceCache = _memoryCache.Get<List<string>>(CacheKey);
|
||||
if (mediaServiceCache == null)
|
||||
{
|
||||
mediaServiceCache = new List<string>();
|
||||
}
|
||||
mediaServiceCache.Add(cacheKey);
|
||||
_memoryCache.Remove(CacheKey);
|
||||
_memoryCache.Add(CacheKey, mediaServiceCache);
|
||||
_memoryCache.Set(CacheKey, mediaServiceCache);
|
||||
}
|
||||
|
||||
public async Task Purge()
|
||||
{
|
||||
var keys = await _memoryCache.GetAsync<List<string>>(CacheKey);
|
||||
var keys = _memoryCache.Get<List<string>>(CacheKey);
|
||||
if (keys == null)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace Ombi
|
|||
//{
|
||||
// setup.AddHealthCheckEndpoint("Ombi", "/health");
|
||||
//});
|
||||
services.AddMemoryCache();
|
||||
services.AddLazyCache();
|
||||
services.AddHttpClient();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue