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. 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.
我在使用ASP.NET MVC框架时相当新,并且希望在缓存我的MVC Web应用程序的各个部分时能够找到一些关于最佳实践的帮助。我知道堆栈溢出使用MVC和一些相当漂亮的令人敬畏的缓存技术,并且它的MILES比我的应用程序更快,即使在本地运行时也是如此。
I have a few questions.
我有几个问题。
-
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?
缓存实际上是如何工作的,以及如何“启用”它,以及各种选项有哪些。什么是最好的缓存使用?
-
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? What best practises have you guys found when having to deal with this issue?
我的应用程序有很多数据库事务,列表定期更改。我担心页面刷新的严重性,用户没有获得最新版本的数据。什么是在Web应用程序速度和显示“最新”数据之间取得平衡的最佳方法?你们在处理这个问题时发现了哪些最佳做法?
-
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如何去做这个。
-
I am using the Castle.Windor integration to the controllers, I am not sure if this changes anything.
我正在使用Castle.Windor集成到控制器,我不确定这是否会改变任何东西。
-
Any other best practises of notes of things to be wary/careful of would be greatly appreciated.
任何其他需要警惕/谨慎的事情的最佳做法将不胜感激。
3 个解决方案
#1
3
You might want to take a look at Phil Haack post for some donut caching. He's THE reference for ASP.NET MVC :)
您可能想看看Phil Haack的帖子,以获得一些甜甜圈缓存。他是ASP.NET MVC的参考:)
#2
2
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.
而这样的例子不胜枚举。
#3
1
You can easily cache views using the OutputCache attribute. Any not frequently updated lists I cache as well using nHibernate caching mechanisms.
您可以使用OutputCache属性轻松缓存视图。任何不经常更新的列表我也使用nHibernate缓存机制进行缓存。
#1
3
You might want to take a look at Phil Haack post for some donut caching. He's THE reference for ASP.NET MVC :)
您可能想看看Phil Haack的帖子,以获得一些甜甜圈缓存。他是ASP.NET MVC的参考:)
#2
2
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.
而这样的例子不胜枚举。
#3
1
You can easily cache views using the OutputCache attribute. Any not frequently updated lists I cache as well using nHibernate caching mechanisms.
您可以使用OutputCache属性轻松缓存视图。任何不经常更新的列表我也使用nHibernate缓存机制进行缓存。