缓存策略,输出缓存与数据缓存还是两者兼而有之? [英] Caching strategy, Output Cache vs Data Cache or both?

查看:30
本文介绍了缓存策略,输出缓存与数据缓存还是两者兼而有之?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个 ASP.NET MVC 项目,现在我想开始考虑我的缓存策略.我试图让我的框架尽可能开放,以便在缓存中使用.

I'm working on an ASP.NET MVC project and I've come to the point where I want to start considering my caching strategy. I've tried to leave my framework as open as possible for the use in caching.

据我在 Scott Hanselman 的播客 StackOverflow.com 中听到的消息,StackOverflow.com 使用页面输出缓存并将内容压缩并将其放入 RAM.这听起来很适合用户范围的缓存,但对于个性化页面之类的内容,您必须为每个用户缓存一个版本,这可能会很快失控.

From what I heard during Scott Hanselman's podcast StackOverflow.com uses page output caching and zips that content and puts it into RAM. This sounds like this would be great for user-wide cache but for something like personalized pages you would have to cache a version for each user and that could get out of control very quickly.

所以,对于缓存策略.应该使用哪个,输出缓存,数据缓存或组合?我的第一个想法是两者,但就缓存依赖而言,听起来可能有点复杂.

So, for a caching strategy. Which should be used, Output Caching, Data Caching or combined? My first thoughts are both but as far as cache dependencies it sounds like it could get a bit complex.

推荐答案

小心过度的缓存.虽然缓存是一种有助于提高性能的工具,但如果使用不当,实际上会使性能变差.

Be careful about over-aggressive caching. Although caching is a tool for helping performance, when used incorrectly, it can actually make performance worse.

如果不了解有关您的项目的更多详细信息,我无法回答输出缓存或数据缓存是否更适合您.我可以帮助提供几个示例,说明何时使用一个而不是另一个.

I can't answer whether output caching or data caching would work for you better without knowing more details about your project. I can help provide a couple examples of when to use one over another.

如果您有一个经常在许多不同视图中使用的特定数据集,最好使用数据缓存.如果您的数据获取操作相对于您的数据呈现而言非常常见且昂贵,则您会使用它.如果您有多个使用相同数据的视图,则可以节省数据获取时间.

If you have a specific data set which you would use often in many different views, you'd be better off using data caching. You'd use this if your data fetch operation was very common and expensive relative to your data rendering. If you had multiple views which used the same data, you would save your data fetching time.

如果您有一个使用非常具体的数据集的视图,并且该视图的呈现很复杂,并且该视图经常被请求(例如,堆栈溢出的主页),那么您将从输出缓存中受益匪浅.

If you had a view which used a very specific data set and the rendering of the view was complicated and this view was requested very often (for example, stack overflow's home page), then you would benefit a lot from output caching.

所以最后,这真的取决于你的需要,小心不要错误地使用缓存.

So in the end, it really depends on your needs and be careful about using caching incorrectly.

这篇关于缓存策略,输出缓存与数据缓存还是两者兼而有之?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆