-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change
DisableLogging
to ConfigureLogging
and don't use negative …
…names
- Loading branch information
Showing
12 changed files
with
492 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 72 additions & 72 deletions
144
src/Tests/EFCoreSecondLevelCacheInterceptor.AspNetCoreSample/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,92 @@ | ||
using System; | ||
using EFCoreSecondLevelCacheInterceptor.Tests.DataLayer; | ||
using EFCoreSecondLevelCacheInterceptor.Tests.DataLayer.Utils; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using EFCoreSecondLevelCacheInterceptor.Tests.DataLayer; | ||
using EFCoreSecondLevelCacheInterceptor.Tests.DataLayer.Entities; | ||
using System; | ||
|
||
namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample | ||
namespace EFCoreSecondLevelCacheInterceptor.AspNetCoreSample; | ||
|
||
public class Startup | ||
{ | ||
public class Startup | ||
private readonly string _contentRootPath; | ||
private readonly IWebHostEnvironment _env; | ||
|
||
public Startup(IConfiguration configuration, IWebHostEnvironment env) | ||
{ | ||
private readonly string _contentRootPath; | ||
_env = env; | ||
_contentRootPath = env.ContentRootPath; | ||
Configuration = configuration; | ||
} | ||
|
||
public Startup(IConfiguration configuration, IWebHostEnvironment env) | ||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddEFSecondLevelCache(options => | ||
{ | ||
_contentRootPath = env.ContentRootPath; | ||
Configuration = configuration; | ||
} | ||
options.UseMemoryCacheProvider(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30)) | ||
.ConfigureLogging(_env.IsDevelopment()) | ||
|
||
//.CacheAllQueries(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30) | ||
/*.CacheQueriesContainingTypes( | ||
CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30), | ||
typeof(Post), typeof(Product), typeof(User) | ||
)*/ | ||
.CacheQueriesContainingTableNames(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30), | ||
TableNameComparison.ContainsOnly, "posts", "products", "users").SkipCachingCommands(commandText => | ||
|
||
// How to skip caching specific commands | ||
commandText.Contains("NEWID()", StringComparison.InvariantCultureIgnoreCase)) | ||
|
||
// Don't cache null values. Remove this optional setting if it's not necessary. | ||
.SkipCachingResults(result | ||
=> result.Value == null || (result.Value is EFTableRows rows && rows.RowsCount == 0)) | ||
.SkipCacheInvalidationCommands(commandText => | ||
|
||
public IConfiguration Configuration { get; } | ||
// How to skip invalidating the related cache entries of this query | ||
commandText.Contains("NEWID()", StringComparison.InvariantCultureIgnoreCase)); | ||
}); | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
var connectionString = Configuration["ConnectionStrings:ApplicationDbContextConnection"]; | ||
|
||
if (connectionString.Contains("%CONTENTROOTPATH%")) | ||
{ | ||
services.AddEFSecondLevelCache(options => | ||
{ | ||
options.UseMemoryCacheProvider(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30)) | ||
.DisableLogging(false) | ||
//.CacheAllQueries(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30) | ||
/*.CacheQueriesContainingTypes( | ||
CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30), | ||
typeof(Post), typeof(Product), typeof(User) | ||
)*/ | ||
.CacheQueriesContainingTableNames( | ||
CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30), | ||
TableNameComparison.ContainsOnly, | ||
"posts", "products", "users" | ||
) | ||
.SkipCachingCommands(commandText => | ||
// How to skip caching specific commands | ||
commandText.Contains("NEWID()", StringComparison.InvariantCultureIgnoreCase)) | ||
// Don't cache null values. Remove this optional setting if it's not necessary. | ||
.SkipCachingResults(result => | ||
result.Value == null || (result.Value is EFTableRows rows && rows.RowsCount == 0)) | ||
.SkipCacheInvalidationCommands(commandText => | ||
// How to skip invalidating the related cache entries of this query | ||
commandText.Contains("NEWID()", StringComparison.InvariantCultureIgnoreCase)); | ||
}); | ||
|
||
var connectionString = Configuration["ConnectionStrings:ApplicationDbContextConnection"]; | ||
if (connectionString.Contains("%CONTENTROOTPATH%")) | ||
{ | ||
connectionString = connectionString.Replace("%CONTENTROOTPATH%", _contentRootPath); | ||
} | ||
services.AddConfiguredMsSqlDbContext(connectionString); | ||
|
||
services.AddControllersWithViews(); | ||
connectionString = connectionString.Replace("%CONTENTROOTPATH%", _contentRootPath); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, | ||
IServiceScopeFactory scopeFactory) | ||
services.AddConfiguredMsSqlDbContext(connectionString); | ||
|
||
services.AddControllersWithViews(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceScopeFactory scopeFactory) | ||
{ | ||
scopeFactory.Initialize(); | ||
scopeFactory.SeedData(); | ||
|
||
if (env.IsDevelopment()) | ||
{ | ||
scopeFactory.Initialize(); | ||
scopeFactory.SeedData(); | ||
|
||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
app.UseHsts(); | ||
} | ||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllerRoute( | ||
name: "default", | ||
pattern: "{controller=Home}/{action=Index}/{id?}"); | ||
}); | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
app.UseHsts(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
b549903
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is in fact a breaking change and would require you to bump the version to 5.x.x. It's probably too late for that now, but it would be useful to update the docs, which still mention
DisableLogging
.