@@ -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