fix: cache
This commit is contained in:
parent
0ca91fb6df
commit
b8ab7948a9
29
Program.cs
29
Program.cs
@ -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>();
|
||||
}
|
||||
|
||||
// ✅ 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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user