fix: cache
This commit is contained in:
parent
0ca91fb6df
commit
b8ab7948a9
33
Program.cs
33
Program.cs
@ -20,6 +20,7 @@ using Serilog.Events;
|
|||||||
using Serilog.Sinks.SystemConsole.Themes;
|
using Serilog.Sinks.SystemConsole.Themes;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
using Microsoft.AspNetCore.Mvc.Razor;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -81,30 +82,14 @@ else
|
|||||||
builder.Services.AddScoped<MongoDbContext>();
|
builder.Services.AddScoped<MongoDbContext>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache Configuration - use Redis if available, otherwise memory cache
|
builder.Services.AddMemoryCache();
|
||||||
var redisConnectionString = builder.Configuration.GetConnectionString("Redis");
|
builder.Services.AddSingleton<IDistributedCache, MemoryDistributedCacheWrapper>();
|
||||||
if (!string.IsNullOrEmpty(redisConnectionString))
|
|
||||||
{
|
// ✅ DataProtection compartilhado via FileSystem (ADICIONAR APÓS O CACHE)
|
||||||
try
|
builder.Services.AddDataProtection()
|
||||||
{
|
.PersistKeysToFileSystem(new DirectoryInfo("/app/keys"))
|
||||||
builder.Services.AddStackExchangeRedisCache(options =>
|
.SetApplicationName("QRRapido");
|
||||||
{
|
|
||||||
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>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Authentication Configuration
|
// Authentication Configuration
|
||||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user