ICacheManager in Autofac as InstancePerHttpRequest?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi,

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.
12 years ago
Sure, you're right. I've just updated the code. Thanks!
12 years ago
Andrei,

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.
12 years ago
Yes, it's old issue. And that's why all entities are not cached between requests. Find more info here.

But MemoryCacheManager caches only locales and settings. But we don't pass these entities to appropriate services when updating.
12 years ago
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.