Possibility to allow caching with explicit transactions
bjarne-callewaert opened this issue · 1 comments
Summary of the issue
When re-enabling this EFCoreSecondLevelCacheInterceptor (after disabling it for a while because of some parsing issues on the Oracle side), we noticed that none of our queries were cached anymore.
In this commit Don't cache an explicit transaction, queries that are executed inside an explicit transaction are excluded from caching.
We understand there were certain issues/risks that could occur before these changes, but in our case these risks have no chance of occurring:
- Inside each transaction, we only perform 1 SaveChanges
- The SaveChanges happens right before the CommitTransaction
- We only cache projected models, not entities
- No caching is used when performing updates/inserts/deletes
We had a look in our team and for us it would be convenient to keep on using this library because we believe it's very powerful and easy-to-use.
We saw two possibilities to be able to use caching while using explicit transactions:
- Provide an option to allow caching when transactions are used (with documentation about the possible dangers/risks)
- Add a new extension method on EFCoreSecondLevelCacheOptions
.AllowCachingWithExplicitTransactions()
- Add a boolean property on EFCoreSecondLevelCacheSettings called
CachingAllowedWithExplicitTransactions
- Add a new extension method on EFCoreSecondLevelCacheOptions
- Always allow caching in the library, even when using explicit transactions, but only when no SaveChanges has happened
- Count the amount of times SaveChanges has occured (DbContext events, ...)
- or check the DbContext about .HasChanges()
- or ...
- ...
Would that be something you would be open to if this is implemented? If yes, what suggestion has your preference?
Kind regards,
Bjarne
Environment
.NET (Core) SDK version: All
Microsoft.EntityFrameworkCore version: All
EFCoreSecondLevelCacheInterceptor version: 3.8.2
Database: Oracle 11g
Cache provider: in-memory
Thanks a lot