diff --git a/backend/packagegroups/NuGet.props b/backend/packagegroups/NuGet.props index 82b74f8b1a1..5b7d4b031da 100644 --- a/backend/packagegroups/NuGet.props +++ b/backend/packagegroups/NuGet.props @@ -40,6 +40,7 @@ + diff --git a/backend/src/Designer/Designer.csproj b/backend/src/Designer/Designer.csproj index f5ac5593f92..5c1a057d3e8 100644 --- a/backend/src/Designer/Designer.csproj +++ b/backend/src/Designer/Designer.csproj @@ -26,6 +26,7 @@ + diff --git a/backend/src/Designer/Infrastructure/Models/PostgreSQLSettings.cs b/backend/src/Designer/Infrastructure/Models/PostgreSQLSettings.cs index de0e790dfd7..a89ce3c9ce6 100644 --- a/backend/src/Designer/Infrastructure/Models/PostgreSQLSettings.cs +++ b/backend/src/Designer/Infrastructure/Models/PostgreSQLSettings.cs @@ -16,5 +16,10 @@ public class PostgreSQLSettings : ISettingsMarker /// Password for app user for the postgres db /// public string DesignerDbPwd { get; set; } + + public string FormattedConnectionString() + { + return string.Format(ConnectionString, DesignerDbPwd); + } } } diff --git a/backend/src/Designer/Infrastructure/ServiceRegistration.cs b/backend/src/Designer/Infrastructure/ServiceRegistration.cs index 33dfce06b31..e91ca200073 100644 --- a/backend/src/Designer/Infrastructure/ServiceRegistration.cs +++ b/backend/src/Designer/Infrastructure/ServiceRegistration.cs @@ -48,10 +48,7 @@ public static IServiceCollection RegisterServiceImplementations(this IServiceCol services.AddDbContext(options => { PostgreSQLSettings postgresSettings = configuration.GetSection(nameof(PostgreSQLSettings)).Get(); - string connectionString = string.Format( - postgresSettings.ConnectionString, - postgresSettings.DesignerDbPwd); - options.UseNpgsql(connectionString); + options.UseNpgsql(postgresSettings.FormattedConnectionString()); }); services.AddScoped(); diff --git a/backend/src/Designer/Middleware/UserRequestSynchronization/RequestSyncExtensions.cs b/backend/src/Designer/Middleware/UserRequestSynchronization/RequestSyncExtensions.cs index 25a1acb882a..f02b319d275 100644 --- a/backend/src/Designer/Middleware/UserRequestSynchronization/RequestSyncExtensions.cs +++ b/backend/src/Designer/Middleware/UserRequestSynchronization/RequestSyncExtensions.cs @@ -24,10 +24,7 @@ public static IServiceCollection RegisterSynchronizationServices(this IServiceCo services.AddSingleton(_ => { PostgreSQLSettings postgresSettings = configuration.GetSection(nameof(PostgreSQLSettings)).Get(); - string connectionString = string.Format( - postgresSettings.ConnectionString, - postgresSettings.DesignerDbPwd); - return new PostgresDistributedSynchronizationProvider(connectionString); + return new PostgresDistributedSynchronizationProvider(postgresSettings.FormattedConnectionString()); }); return services; } diff --git a/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Down/01-drop-distributedcache-table.sql b/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Down/01-drop-distributedcache-table.sql index 79063bbe9db..c0425700d59 100644 --- a/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Down/01-drop-distributedcache-table.sql +++ b/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Down/01-drop-distributedcache-table.sql @@ -1 +1 @@ -DROP TABLE IF EXISTS designer.distribuedcache; +DROP TABLE IF EXISTS designer.distributedcache; diff --git a/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Up/01-setup-distributedcache-table.sql b/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Up/01-setup-distributedcache-table.sql index 6091b2d7c18..914c1d83eb0 100644 --- a/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Up/01-setup-distributedcache-table.sql +++ b/backend/src/Designer/Migrations/SqlScripts/DistributedCache/Up/01-setup-distributedcache-table.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS designer.distribuedcache +CREATE TABLE IF NOT EXISTS designer.distributedcache ( "Id" text COLLATE pg_catalog."default" NOT NULL, "Value" bytea, diff --git a/backend/src/Designer/Program.cs b/backend/src/Designer/Program.cs index 4ef468a331a..b90669b0706 100644 --- a/backend/src/Designer/Program.cs +++ b/backend/src/Designer/Program.cs @@ -19,6 +19,7 @@ using Altinn.Studio.Designer.Services.Interfaces; using Altinn.Studio.Designer.Tracing; using Altinn.Studio.Designer.TypedHttpClients; +using Community.Microsoft.Extensions.Caching.PostgreSql; using Microsoft.ApplicationInsights.Extensibility; using Microsoft.ApplicationInsights.Extensibility.EventCounterCollector; using Microsoft.AspNetCore.Builder; @@ -264,6 +265,19 @@ void ConfigureServices(IServiceCollection services, IConfiguration configuration services.AddFeatureManagement(); services.RegisterSynchronizationServices(configuration); + // Override the default distributed cache with a PostgreSQL implementation + services.AddDistributedPostgreSqlCache(setup => + { + PostgreSQLSettings postgresSettings = + configuration.GetSection(nameof(PostgreSQLSettings)).Get(); + + setup.ConnectionString = postgresSettings.FormattedConnectionString(); + setup.SchemaName = "designer"; + setup.TableName = "distributedcache"; + setup.DisableRemoveExpired = false; + setup.CreateInfrastructure = false; + setup.ExpiredItemsDeletionInterval = TimeSpan.FromMinutes(30); + }); if (!env.IsDevelopment()) { diff --git a/backend/src/Designer/Repository/DeploymentRepository.cs b/backend/src/Designer/Repository/DeploymentRepository.cs index 03e1288b262..bc25f553fff 100644 --- a/backend/src/Designer/Repository/DeploymentRepository.cs +++ b/backend/src/Designer/Repository/DeploymentRepository.cs @@ -32,9 +32,7 @@ public class DeploymentRepository : IDeploymentRepository /// public DeploymentRepository(PostgreSQLSettings postgresSettings, ILogger logger) { - _connectionString = string.Format( - postgresSettings.ConnectionString, - postgresSettings.DesignerDbPwd); + _connectionString = postgresSettings.FormattedConnectionString(); _logger = logger; } diff --git a/backend/src/Designer/Repository/ReleaseRepository.cs b/backend/src/Designer/Repository/ReleaseRepository.cs index 566f1cbd314..5f928eb9b5b 100644 --- a/backend/src/Designer/Repository/ReleaseRepository.cs +++ b/backend/src/Designer/Repository/ReleaseRepository.cs @@ -34,9 +34,7 @@ public class ReleaseRepository : IReleaseRepository /// public ReleaseRepository(PostgreSQLSettings postgresSettings, ILogger logger) { - _connectionString = string.Format( - postgresSettings.ConnectionString, - postgresSettings.DesignerDbPwd); + _connectionString = postgresSettings.FormattedConnectionString(); _logger = logger; }