From 3c661c61d25f80c41c23e4b8c4919748fd68ebab Mon Sep 17 00:00:00 2001 From: Brant DeBow Date: Tue, 30 Dec 2025 18:00:31 -0500 Subject: [PATCH 1/2] Disable database distributed cache in non-self-hosted environments --- src/SharedWeb/Utilities/ServiceCollectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs index 91047d98bcf8..5de834a7a26e 100644 --- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs +++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs @@ -675,7 +675,7 @@ public static void AddDistributedCache( options.Configuration = globalSettings.DistributedCache.Redis.ConnectionString; }); } - else + else if (globalSettings.SelfHosted) { var (databaseProvider, databaseConnectionString) = GetDatabaseProvider(globalSettings); if (databaseProvider == SupportedDatabaseProviders.SqlServer) From 9d1005b1c330e5888609998856d4d38f4c8fbb5f Mon Sep 17 00:00:00 2001 From: Brant DeBow Date: Wed, 31 Dec 2025 10:22:28 -0500 Subject: [PATCH 2/2] Added distributed memory cache as a final fallback option --- .../Utilities/ServiceCollectionExtensions.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs index 5de834a7a26e..8f5dfdf3f4cb 100644 --- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs +++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs @@ -661,8 +661,9 @@ public static void AddIpRateLimiting(this IServiceCollection services, } /// - /// Adds an implementation of to the service collection. Uses a memory - /// cache if self hosted or no Redis connection string is available in GlobalSettings. + /// Adds an implementation of to the service collection. Uses Redis + /// if a connection string is available in GlobalSettings, a database-backed distributed cache if + /// self-hosted or a distributed memory cache as a final fallback. /// public static void AddDistributedCache( this IServiceCollection services, @@ -675,21 +676,28 @@ public static void AddDistributedCache( options.Configuration = globalSettings.DistributedCache.Redis.ConnectionString; }); } - else if (globalSettings.SelfHosted) + else { - var (databaseProvider, databaseConnectionString) = GetDatabaseProvider(globalSettings); - if (databaseProvider == SupportedDatabaseProviders.SqlServer) + if (globalSettings.SelfHosted) { - services.AddDistributedSqlServerCache(o => + var (databaseProvider, databaseConnectionString) = GetDatabaseProvider(globalSettings); + if (databaseProvider == SupportedDatabaseProviders.SqlServer) { - o.ConnectionString = databaseConnectionString; - o.SchemaName = "dbo"; - o.TableName = "Cache"; - }); + services.AddDistributedSqlServerCache(o => + { + o.ConnectionString = databaseConnectionString; + o.SchemaName = "dbo"; + o.TableName = "Cache"; + }); + } + else + { + services.AddSingleton(); + } } else { - services.AddSingleton(); + services.AddDistributedMemoryCache(); } }