Add project
This commit is contained in:
16
Api/Extensions/CacheExtensions.cs
Normal file
16
Api/Extensions/CacheExtensions.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Common.Extensions;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Api.Extensions;
|
||||
|
||||
public static class CacheExtensions
|
||||
{
|
||||
public static async Task SetWithExpirationTimeAsync<T>(this IDistributedCache cache, string key, T value, int minutes = 10)
|
||||
{
|
||||
var options = new DistributedCacheEntryOptions()
|
||||
.SetAbsoluteExpiration(TimeSpan.FromMinutes(minutes));
|
||||
|
||||
await cache.SetStringAsync(key, value.ToJson(), options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user