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);
    }
}
