How to access cache instance in DbConfiguration from DbContext?
UweKeim opened this issue · comments
Trying to delete all items from the cache, I've read this discussion.
Ideally, I want to create a method ClearCache()
in my DbContext
-derived class which in turn accesses the InMemoryCache
instance inside my DbConfiguration
-derived class.
What I'm struggling with is:
How to get a reference to my DbConfiguration
-derived class from within my DbContext
-derived class?
I've also asked on SO but maybe I'm on the completely wrong path?
Just store a reference to the cache in a static variable before you pass it to the CacheTransactionHandler
ctor and then you should be able to it access from anywhere. The cache is effectively singleton so I don't think there is any problem with doing this.
Thanks a lot.