mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:26:31 +00:00
failsafe load dlls
add user config queue offsets throttle improvements
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using LazyCache;
|
||||
|
||||
namespace Azaion.CommonSecurity.Services;
|
||||
|
||||
public interface ICache
|
||||
{
|
||||
T GetFromCache<T>(string key, Func<T> fetchFunc, TimeSpan? expiration = null);
|
||||
void Invalidate(string key);
|
||||
}
|
||||
|
||||
public class MemoryCache : ICache
|
||||
{
|
||||
private readonly IAppCache _cache = new CachingService();
|
||||
|
||||
public T GetFromCache<T>(string key, Func<T> fetchFunc, TimeSpan? expiration = null)
|
||||
{
|
||||
expiration ??= TimeSpan.FromHours(4);
|
||||
return _cache.GetOrAdd(key, entry =>
|
||||
{
|
||||
var result = fetchFunc();
|
||||
entry.AbsoluteExpirationRelativeToNow = expiration;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public void Invalidate(string key) => _cache.Remove(key);
|
||||
}
|
||||
Reference in New Issue
Block a user