Entity Framework: Cache management?

北城余情 提交于 2019-12-24 01:16:37

问题


I'm using Entity Framework 4.0 behind WCF services. My problem is that the memory used by the programm is growing a lot(start à 200Mo, and I stopped it at ~1.1Go.

How can I manage the cache? I mean, I've two datacontext, one of them is never used to read data, so can I disable the cache?

And for the other, can I specify the amount of space it cans use? Is there a way to monitor these resources? Is there a way to use less resources?

Thank you!


回答1:


First of all you should not use shared contexts. Create new context for each WCF request and dispose context before you end your operation processing! If you need some data caching do it outside of EF. EF itself is not supposed to be used as cache and there is no control of this behavior.

If you host your service in IIS you can configure AppPool recycling by specifying Private Memory Limit in advanced settings of the AppPool. But it will simply kill everything running in that AppPool.




回答2:


What may be happening is that each call is creating a new context. Which remains in memory untill the connection timesout and the Garbage collection removes it.

  • Are you not disposing of the datacontext each time you use it?
  • Are you closing your connections from the client?
  • Are you using per call session mode?


来源:https://stackoverflow.com/questions/4872911/entity-framework-cache-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!