mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:56:31 +00:00
0c66607ed7
add user config queue offsets throttle improvements
27 lines
715 B
C#
27 lines
715 B
C#
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);
|
|
} |