简体   繁体   English

ASP.NET MVC框架中的缓存

[英]Caching in the ASP.NET MVC Framework

I am fairly new at using the ASP.NET MVC framework and was hoping that I could find some help about best-practises when caching various parts of my MVC web application. 我在使用ASP.NET MVC框架时相当新,并且希望在缓存我的MVC Web应用程序的各个部分时能够找到一些关于最佳实践的帮助。 I know that stack overflow uses MVC and some pretty freeking awesome caching techniques, and its MILES faster than my app, even when running locally. 我知道堆栈溢出使用MVC和一些相当漂亮的令人敬畏的缓存技术,并且它的MILES比我的应用程序更快,即使在本地运行时也是如此。

I have a few questions. 我有几个问题。

  1. How does the caching actually work, and how do you "enable" it, and what are the various options. 缓存实际上是如何工作的,以及如何“启用”它,以及各种选项有哪些。 What is the best kind of caching to use? 什么是最好的缓存使用?

  2. My app has a lot of database transactions, lists that regularly change. 我的应用程序有很多数据库事务,列表定期更改。 I am worried about the timliness of page refreshes, in users not getting the most recent version of the data. 我担心页面刷新的严重性,用户没有获得最新版本的数据。 Whats the best way to strike a balance between web application speed and displaying "up-to-date" data? 什么是在Web应用程序速度和显示“最新”数据之间取得平衡的最佳方法? What best practises have you guys found when having to deal with this issue? 你们在处理这个问题时发现了哪些最佳做法?

  3. How do I cache different parts (I assume views) with different caching settings? 如何使用不同的缓存设置缓存不同的部分(我假设视图)? I assume that it could be done with sub-controllers, but I have NFI how to go about doing this. 我假设它可以用子控制器完成,但我有NFI如何去做这个。

  4. I am using the Castle.Windor integration to the controllers, I am not sure if this changes anything. 我正在使用Castle.Windor集成到控制器,我不确定这是否会改变任何东西。

  5. Any other best practises of notes of things to be wary/careful of would be greatly appreciated. 任何其他需要警惕/谨慎的事情的最佳做法将不胜感激。

You might want to take a look at Phil Haack post for some donut caching. 您可能想看看Phil Haack的帖子,以获得一些甜甜圈缓存。 He's THE reference for ASP.NET MVC :) 他是ASP.NET MVC的参考:)

From a "best practices" perspective, you will need to consider the same things you must consider in any application that uses caching. 从“最佳实践”的角度来看,您需要考虑在使用缓存的任何应用程序中必须考虑的相同事项。

  • Is the traffic volume high enough to benefit from caching? 流量是否足够高,可以从缓存中受益?
  • How often does a particular piece of data change? 特定数据的变化频率如何? How crucial is timeliness? 及时性有多重要?
  • Do I own the data-access layer? 我是否拥有数据访问层? If so, can I trigger the refresh in the cache by the actual changing of the data and avoid a time-based expiration? 如果是这样,我是否可以通过实际更改数据来触发缓存中的刷新并避免基于时间的到期?

and the list goes on. 而这样的例子不胜枚举。

You can easily cache views using the OutputCache attribute. 您可以使用OutputCache属性轻松缓存视图。 Any not frequently updated lists I cache as well using nHibernate caching mechanisms. 任何不经常更新的列表我也使用nHibernate缓存机制进行缓存。

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

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