Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/SharedWeb/Utilities/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,9 @@ public static void AddIpRateLimiting(this IServiceCollection services,
}

/// <summary>
/// Adds an implementation of <see cref="IDistributedCache"/> to the service collection. Uses a memory
/// cache if self hosted or no Redis connection string is available in GlobalSettings.
/// Adds an implementation of <see cref="IDistributedCache"/> 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.
/// </summary>
public static void AddDistributedCache(
this IServiceCollection services,
Expand All @@ -677,19 +678,26 @@ public static void AddDistributedCache(
}
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<IDistributedCache, EntityFrameworkCache>();
}
}
else
{
services.AddSingleton<IDistributedCache, EntityFrameworkCache>();
services.AddDistributedMemoryCache();
}
}

Expand Down
Loading