You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Thank you.
comments
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]
Thank you.
However, I noticed that the cache is not persisted using using BeginTransaction() within a loop.
For example:
// 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()){try{// entity framework queries here// commit
databaseTransaction.Commit();}catch(Exception){// rollback
databaseTransaction.Rollback();throw;}}}
Thank you.
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
Thank you
Sorry, I don't offer consulting services. It also has been a few years since I did any serious development for .NET and re-focusing would require time I cannot afford at the moment.
Ported from: https://efcache.codeplex.com/workitem/10
REPORTED ON:
REPORTED BY:
Nov 5, 2014 at 7:28 PM
icnocop (contact)
Hi.
Thank you for EFCache.
I'd like to request support for caching within a transaction scope.
EDIT [moozzyk]
The code snippet is irrelevant since it does not use
TransactionScope
and should work correctly; See my comment below./EDIT
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.
Thank you.
comments
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]
Thank you.
However, I noticed that the cache is not persisted using using BeginTransaction() within a loop.
For example:
Thank you.
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: