| | |
| | | { |
| | | public class MemoryCacheService : ICacheService |
| | | { |
| | | protected IMemoryCache _cache; |
| | | private readonly IMemoryCache _cache; |
| | | |
| | | public MemoryCacheService(IMemoryCache cache) |
| | | { |
| | | _cache = cache; |
| | | |
| | | _cache = cache ?? throw new ArgumentNullException(nameof(cache)); |
| | | } |
| | | |
| | | public bool Add(string key, string value, int expireSeconds = -1, bool isSliding = false) |
| | |
| | | |
| | | public void Dispose() |
| | | { |
| | | if (_cache != null) |
| | | _cache.Dispose(); |
| | | _cache?.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | |
| | | return _cache.Get(key) != null; |
| | | } |
| | | |
| | | public T Get<T>(string key) where T : class |
| | | public T? Get<T>(string key) where T : class |
| | | { |
| | | if (key == null) |
| | | { |