简体   繁体   English

实体框架:缓存管理?

[英]Entity Framework: Cache management?

I'm using Entity Framework 4.0 behind WCF services. 我在WCF服务后面使用Entity Framework 4.0。 My problem is that the memory used by the programm is growing a lot(start à 200Mo, and I stopped it at ~1.1Go. 我的问题是程序使用的内存正在增长很多(从à200Mo开始,我在〜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? 我的意思是,我有两个datacontext,其中一个从不用于读取数据,因此可以禁用缓存吗?

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! 谢谢!

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! 在结束操作处理之前,为每个WCF请求创建新上下文并处置上下文! If you need some data caching do it outside of EF. 如果您需要一些数据缓存,请在EF之外进行。 EF itself is not supposed to be used as cache and there is no control of this behavior. EF本身不应该用作缓存,并且无法控制此行为。

If you host your service in IIS you can configure AppPool recycling by specifying Private Memory Limit in advanced settings of the AppPool. 如果将服务托管在IIS中,则可以通过在AppPool的高级设置中指定“专用内存限制”来配置AppPool回收。 But it will simply kill everything running in that AppPool. 但这只会杀死该AppPool中运行的所有内容。

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? 您是否使用按通话会话模式?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM