fix: cache
All checks were successful
Deploy QR Rapido / test (push) Successful in 40s
Deploy QR Rapido / build-and-push (push) Successful in 13m14s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Successful in 1m38s

This commit is contained in:
Ricardo Carneiro 2025-08-24 23:30:45 -03:00
parent 0ca91fb6df
commit b8ab7948a9

View File

@ -20,6 +20,7 @@ using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.DataProtection;
var builder = WebApplication.CreateBuilder(args);
@ -81,30 +82,14 @@ else
builder.Services.AddScoped<MongoDbContext>();
}
// Cache Configuration - use Redis if available, otherwise memory cache
var redisConnectionString = builder.Configuration.GetConnectionString("Redis");
if (!string.IsNullOrEmpty(redisConnectionString))
{
try
{
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = redisConnectionString;
});
}
catch
{
// Fallback to memory cache if Redis fails
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<IDistributedCache, QRRapidoApp.Services.MemoryDistributedCacheWrapper>();
}
}
else
{
// Use memory cache when Redis is not configured
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<IDistributedCache, MemoryDistributedCacheWrapper>();
}
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<IDistributedCache, MemoryDistributedCacheWrapper>();
// ✅ DataProtection compartilhado via FileSystem (ADICIONAR APÓS O CACHE)
builder.Services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("/app/keys"))
.SetApplicationName("QRRapido");
// Authentication Configuration
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)