@ -16,21 +16,28 @@ public static class ServiceCollectionExtensions
/// Adds the <see cref="IDbContextFactory{TContext}"/> interface to the service collection with second level caching enabled.
/// Adds the <see cref="IDbContextFactory{TContext}"/> interface to the service collection with second level caching enabled.
/// </summary>
/// </summary>
/// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param>
/// <param name="serviceCollection">An instance of the <see cref="IServiceCollection"/> interface.</param>
/// <param name="disableSecondLevelCache">Whether second level cache disabled..</param>
/// <returns>The updated service collection.</returns>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddJellyfinDbContext ( this IServiceCollection serviceCollection )
public static IServiceCollection AddJellyfinDbContext ( this IServiceCollection serviceCollection , bool disableSecondLevelCache )
{
{
serviceCollection . AddEFSecondLevelCache ( options = >
if ( ! disableSecondLevelCache )
options . UseMemoryCacheProvider ( )
{
. CacheAllQueries ( CacheExpirationMode . Sliding , TimeSpan . FromMinutes ( 10 ) )
serviceCollection . AddEFSecondLevelCache ( options = >
. UseCacheKeyPrefix ( "EF_" )
options . UseMemoryCacheProvider ( )
// Don't cache null values. Remove this optional setting if it's not necessary.
. CacheAllQueries ( CacheExpirationMode . Sliding , TimeSpan . FromMinutes ( 10 ) )
. SkipCachingResults ( result = > result . Value is null or EFTableRows { RowsCount : 0 } ) ) ;
. UseCacheKeyPrefix ( "EF_" )
// Don't cache null values. Remove this optional setting if it's not necessary.
. SkipCachingResults ( result = > result . Value is null or EFTableRows { RowsCount : 0 } ) ) ;
}
serviceCollection . AddPooledDbContextFactory < JellyfinDbContext > ( ( serviceProvider , opt ) = >
serviceCollection . AddPooledDbContextFactory < JellyfinDbContext > ( ( serviceProvider , opt ) = >
{
{
var applicationPaths = serviceProvider . GetRequiredService < IApplicationPaths > ( ) ;
var applicationPaths = serviceProvider . GetRequiredService < IApplicationPaths > ( ) ;
opt . UseSqlite ( $"Filename={Path.Combine(applicationPaths.DataPath, " jellyfin . db ")}" )
var dbOpt = opt . UseSqlite ( $"Filename={Path.Combine(applicationPaths.DataPath, " jellyfin . db ")}" ) ;
. AddInterceptors ( serviceProvider . GetRequiredService < SecondLevelCacheInterceptor > ( ) ) ;
if ( ! disableSecondLevelCache )
{
dbOpt . AddInterceptors ( serviceProvider . GetRequiredService < SecondLevelCacheInterceptor > ( ) ) ;
}
} ) ;
} ) ;
return serviceCollection ;
return serviceCollection ;