I just noticed that the MemoryCacheManager implementation of ICacheManager is registered in Autofac as an InstancePerHttpRequest. What's the reason behind this choice? I would have thought it would be a SingleInstance.
I noticed that this modification causes some issues as the cached entities are still considered attached to their original DbContext. If you set a reference to them in another object graph, the following error occurs:
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
In this case, the referenced object can be reloaded using the id from the cached object before being assigned in the new object graph. I think that even if we detach the object from the DbContext before cahing it, once we assign it to another object graph it will automatically attach to the other DbContext and the same problem will occur.
Ok yes on my side I've set all cache services as static. I'll just update it per your modification. I'll go and read the post you referenced to be up to date on the issue! Thanks!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.