| 1234567891011121314151617181920212223242526 |
- 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<string>(cacheKey, out var result))
- return result; ;
- return "";
- }
- }
- }
|