Currently, the entity sets that are indicated as cache-able do not behave as being cached when queried and the database is explicitly queried every time.
moozzyk wrote Nov 11, 2014 at 10:37 PM [x]
I agree it would be useful to add support for TransactionScope
However, the code snippet you provided is not relevant for two reasons:
it does not use TransactionScope at all - Database.BeginTransaction() will start a regular DbTransaction and will not create an ambient (potentially distributed) transaction TransactionScope would create
since the code you provided is not using a TransactionScope EF would call the DbTransactionInterceptor on commit and on rollback meaning that the cache would work correctly since it already intercepts transaction calls to invalidate cache on commit
icnocop wrote Dec 23, 2014 at 1:34 PM [x]
However, I noticed that the cache is not persisted using using BeginTransaction() within a loop.
// open database connection for performance reasonsfor (inti=0; i<100; i++)
// the Entity Framework cache is not persisted between items within the for loop// the database is queried for the same data that was previously queried within the DbContextTransaction scope in previous iterationsusing (DbContextTransactiondatabaseTransaction=context.Database.BeginTransaction())
// entity framework queries here// commitdatabaseTransaction.Commit();
moozzyk wrote Dec 26, 2014 at 8:00 PM [x]
Yes, for simplicity results for queries issued inside transactions are not cached (you can see it here: https://github.com/moozzyk/EFCache/blob/master/EFCache/CacheTransactionHandler.cs). This is because I would have to track them separately and merge the when the transaction is committed. In general it is best practice to keep the transaction as short as possible and do as few reads as possible. Note that EF by default will only create a transaction when saving results to the database (i.e. when you call SaveChanges) and won't create transactions for queries.
The text was updated successfully, but these errors were encountered:
Very good job.
Is there any fix to this problem. My business layer is using transactions in all methods and I can't use the cache inside.
Which is the problem?
What would happen if I comment the (transaction == null) check inside GetItem