using Microsoft.AspNetCore.OutputCaching;
using Tiku.Application.Tenancy;

namespace Tiku.Api.Caching;

internal sealed class TenantPublicCacheInvalidator(IOutputCacheStore outputCacheStore)
    : ITenantPublicCacheInvalidator
{
    public async Task InvalidateAsync(Guid tenantId, CancellationToken cancellationToken = default)
    {
        await InvalidateCoreAsync(tenantId, cancellationToken);
    }

    public ValueTask InvalidateCoreAsync(Guid tenantId, CancellationToken cancellationToken)
    {
        return outputCacheStore.EvictByTagAsync($"tenant:{tenantId:N}", cancellationToken);
    }
}