Skip to content

Commit 243a6c6

Browse files
Merge branch 'main' into billing/pm-29610/update-account-storage-endpoint
2 parents ceee636 + cc03842 commit 243a6c6

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,9 @@ public static void AddIpRateLimiting(this IServiceCollection services,
661661
}
662662

663663
/// <summary>
664-
/// Adds an implementation of <see cref="IDistributedCache"/> to the service collection. Uses a memory
665-
/// cache if self hosted or no Redis connection string is available in GlobalSettings.
664+
/// Adds an implementation of <see cref="IDistributedCache"/> to the service collection. Uses Redis
665+
/// if a connection string is available in GlobalSettings, a database-backed distributed cache if
666+
/// self-hosted or a distributed memory cache as a final fallback.
666667
/// </summary>
667668
public static void AddDistributedCache(
668669
this IServiceCollection services,
@@ -677,19 +678,26 @@ public static void AddDistributedCache(
677678
}
678679
else
679680
{
680-
var (databaseProvider, databaseConnectionString) = GetDatabaseProvider(globalSettings);
681-
if (databaseProvider == SupportedDatabaseProviders.SqlServer)
681+
if (globalSettings.SelfHosted)
682682
{
683-
services.AddDistributedSqlServerCache(o =>
683+
var (databaseProvider, databaseConnectionString) = GetDatabaseProvider(globalSettings);
684+
if (databaseProvider == SupportedDatabaseProviders.SqlServer)
684685
{
685-
o.ConnectionString = databaseConnectionString;
686-
o.SchemaName = "dbo";
687-
o.TableName = "Cache";
688-
});
686+
services.AddDistributedSqlServerCache(o =>
687+
{
688+
o.ConnectionString = databaseConnectionString;
689+
o.SchemaName = "dbo";
690+
o.TableName = "Cache";
691+
});
692+
}
693+
else
694+
{
695+
services.AddSingleton<IDistributedCache, EntityFrameworkCache>();
696+
}
689697
}
690698
else
691699
{
692-
services.AddSingleton<IDistributedCache, EntityFrameworkCache>();
700+
services.AddDistributedMemoryCache();
693701
}
694702
}
695703

0 commit comments

Comments
 (0)