I'm refactoring my ASP.NET MVC 4 WebAPI project for performance optimization reasons. Within my controller code, I'm searching for entities in a context (DbContext, EF6). There are a few thousands of such entities, new ones are added on an hourly basis (i.e. "slowly"), they are rarely deleted (and I don't care if deleted entities are still found on the context's cache!) and are never modified.
After reading the answers to this question, to this one and a few more discussions, I'm still not sure it's a bad idea to use a single static DbContext for the purpose described above - a DbContext which never updates the database.
Performance-wise, I'm not worried about the instantiation cost, but rather about the uselessness of caching requested entities if the DbContext is created for each request. I'm also using a 2nd level caching, which makes the persistence of the context even more acute.
My questions are: 1. Regardless of the specific implementation, is a "static" DbContext a valid solution in my case? 2. If so, what would be the most appropriate way of implementing such a DbContext? 3. Should I periodically "flush" the context to clear the cache in order to prevent if from growing too big?