using Microsoft.Extensions.Caching.Distributed; using System; using System.Text; namespace Infrastructure.Extensions { public static class DistributedCacheExtensions { public static void Set(this IDistributedCache cache, object key, T value) { cache.SetString(key.ToString(), value.ToJson(), new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(1) }); } public static T Get(this IDistributedCache cache, object key) { var value = cache.GetString(key.ToString()); if (value != null) { return value.FromJson(); } return default(T); } public static void Remove(this IDistributedCache cache, object key) { cache.Remove(key.ToString()); } } }