Entity Framework: Cache management?

2019-07-19 04:08发布

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!

2条回答
Rolldiameter
2楼-- · 2019-07-19 04:44

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.

查看更多
不美不萌又怎样
3楼-- · 2019-07-19 04:50

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?
查看更多
登录 后发表回答