简体   繁体   English

asp.net mvc 4 cache vs entityframework 6 cache

[英]asp.net mvc 4 cache vs entityframework 6 cache

A friend and I are developing a web application using ASP.NET MVC 4 and EntityFramework 6 . 我和朋友正在使用ASP.NET MVC 4EntityFramework 6开发Web应用程序。 We implemented the Repository Pattern and of course the Entity Framework Context is initialized and removed each time a user makes a request to access data in the database, so caching system entity Framework first level is not exploited . 我们实现了存储库模式,当然每次用户发出访问数据库中数据的请求时,都会初始化并删除实体框架上下文,因此不会利用缓存系统实体Framework第一级。

I want to implement the second level caching in Entity Framework but he tells that it is not necessary, that we can use the ASP.NET Cache. 我想在Entity Framework中实现二级缓存,但他告诉我们没有必要使用ASP.NET Cache。 My question is, 我的问题是,

When to use each type of cache? 何时使用每种类型的缓存?

How fast is each other? 彼此有多快?

when to use each type of cache? 何时使用每种类型的缓存?

There are other performance improvement patterns than writing your own EF provider, which you have to do in order to implement 2nd level cache. 还有其他性能改进模式,而不是编写自己的EF提供程序,为了实现二级缓存,您必须这样做。 My advice (and that's all it is, advice) would be to never implement EF second level cache. 我的建议(这就是建议)将永远不会实现EF二级缓存。

Getting caching right is very difficult, especially cache invalidation. 获得正确的缓存非常困难,尤其是缓存失效。

If your ultimate goal is to deliver web pages quickly, the asp.net cache (or OutputCache) is one way to achieve that. 如果您的最终目标是快速提供网页,那么asp.net缓存(或OutputCache)是实现这一目标的一种方式。 However you then have to choose when to invalidate the cache, which again can be difficult. 但是,您必须选择何时使缓存无效,这也很困难。

how fast is each other? 彼此有多快?

Caches usually store data in RAM because that's the fastest way to get data physically. 缓存通常将数据存储在RAM中,因为这是物理获取数据的最快方法。 However ultimately speed is going to depend. 然而,最终速度将取决于。 What cache provider are you using? 你使用什么缓存提供程序? Is your deployment load-balanced, and if so, do they share the same cache? 您的部署是否负载均衡,如果是,它们是否共享相同的缓存? How do they access it? 他们如何访问它? When you are dealing with the web, you have to consider that the data will be going over the network, so there are all of those latency issues that play a factor too (payload/size, hops, etc.) 当您处理Web时,您必须考虑数据将通过网络传输,因此所有这些延迟问题也会起作用(有效负载/大小,跳数等)

If performance is really a problem, you may want to look into patterns that use tools like redis or other nosql providers to store pre-computed denormalized sets of your data for faster access. 如果性能确实是一个问题,您可能需要查看使用redis或其他nosql提供程序等工具的模式来存储预先计算的非规范化数据集,以便更快地访问。 You can also go outside of EF and craft custom sql for data access points that are giving you particular performance issues. 您还可以访问EF并为自己提供特定性能问题的数据访问点。

I really don't think you are going to get any other answers that don't say "it depends" one way or another. 我真的不认为你会得到任何其他答案,并不是说“它取决于”这样或那样。

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

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