From cc03842f5fae3b5d1ee7a933b4020e5a82cc77dd Mon Sep 17 00:00:00 2001 From: Brant DeBow <125889545+brant-livefront@users.noreply.github.com> Date: Wed, 31 Dec 2025 11:59:59 -0500 Subject: [PATCH] Disable database distributed cache in non-self-hosted environments (#6783) * Disable database distributed cache in non-self-hosted environments * Added distributed memory cache as a final fallback option --- .../Utilities/ServiceCollectionExtensions.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs index 91047d98bc..8f5dfdf3f4 100644 --- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs +++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs @@ -661,8 +661,9 @@ public static class ServiceCollectionExtensions } /// - /// 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, @@ -677,19 +678,26 @@ public static class ServiceCollectionExtensions } 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(); } }