using Microsoft.Extensions.Caching.Memory; namespace Diligent.WebAPI.Host.Extensions { public class CacheModelExtension { private static readonly IMemoryCache _memoryCache = new MemoryCache(new MemoryCacheOptions()); public static void AddCache(string cacheKey, string value, DateTime expiritaion) { var cacheExipiryOptions = new MemoryCacheEntryOptions { AbsoluteExpiration = expiritaion, Priority = CacheItemPriority.High, SlidingExpiration = TimeSpan.FromSeconds(20) }; _memoryCache.Set(cacheKey, value, cacheExipiryOptions); } public static string GetCache(string cacheKey) { if (_memoryCache.TryGetValue(cacheKey, out var result)) return result; ; return ""; } } }