New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can't use Second Level Cache with ABP #6672
Comments
Maybe you can access serviceProvider in your interceptor by following an approach similar to https://stackoverflow.com/a/67003567 |
My friend, it didn't work :( The service provider is needed here This is documentacion of Second Level Cache Interceptor |
I have the same problem. any suggestion? |
@ismcagdas I still can't configure the use of Second Level Cache Interceptor, Cannot find the IServiceCollectionProvider Do you have any suggestions? |
I think you can register IServiceCollectionProvider as explained in the blog post below and then use it in EF core project; https://aspnetzero.com/blog/persist-data-protection-keys-to-database |
I don't work because I need the IServiceProvider and not the IServiceCollectionProvider |
I will try to prepare a sample but it might take some time. |
I've tried this, but it doesn't work. Apparently it is not the same Framework so it does not find the AbpDbContextOptions |
Yes, it is not same. |
@mardemza |
@behiunforgiven |
Have you tried this appraoch ? public static class Issue6672DbContextConfigurer
{
public static void Configure(DbContextOptionsBuilder<Issue6672DbContext> builder, string connectionString)
{
var interceptor = IocManager.Instance.Resolve<SecondLevelCacheInterceptor>();
builder.UseSqlServer(connectionString)
.AddInterceptors(interceptor);
}
public static void Configure(DbContextOptionsBuilder<Issue6672DbContext> builder, DbConnection connection)
{
var interceptor = IocManager.Instance.Resolve<SecondLevelCacheInterceptor>();
builder.UseSqlServer(connection)
.AddInterceptors(interceptor);
}
} |
It runs without problem, but caching does not work. |
In my test, I can see that SecondLevelCacheInterceptor is executed. But, I'm not sure why cache doesn't work. |
@ismcagdas - @behiunforgiven I tried but I didn't have success, it resolves SecondLevelCacheInterceptor well, but then it doesn't cache. |
I will try to check it again. |
So this may not be a SecondLevelCache issue. I created an issue with interceptors not firing Don't know if it is related or not, but thought I would chime in. |
@mardemza I think I figured it out. Since AppService methods and Controller actions are starting a transaction by default (UnitOfWork), you should use services.AddEFSecondLevelCache(options =>
options.UseMemoryCacheProvider()
.ConfigureLogging()
.AllowCachingWithExplicitTransactions(true)
.CacheAllQueries(CacheExpirationMode.Sliding, TimeSpan.FromMinutes(60)) // Does not take effect
); |
@ismcagdas I tried what they told me but it didn't work, it doesn't cache |
I have prepared a sample https://github.com/ismcagdas/Issue6672. Run the project and go to Users page and press the search button several times. You will see that only first request will go to database. |
when i want to update the database I get this error:
|
I cannot implement the Second Level Cache library because it needs to use the service provider and it is not available in the method that configures the
DbContext Configuration.Modules.AbpEfCore().AddDBContext<MyDbContext>(options => ....... ..
And something like this is needed
Configuration.Modules.AbpEfCore().AddDBContext<MyDbContext>((serviceProvider, options) => .......
Can you please help me to find a solution so inside the configurer I can implement this
builder.UseSqlServer(connectionString).AddInterceptors(serviceProvider.GetRequiredService<SecondLevelCacheInterceptor>());
The text was updated successfully, but these errors were encountered: