为什么OutputCache属性需要设置VaryByParam参数?
我对此进行了零研究,我只是好奇。
ASP.NET MVC 中的 OutputCacheAttribute 类需要 Duration 和 VaryByParam 的值。我明白为什么需要 Duration,但不需要 VaryByParam。
I've done zero research on this, I'm just curious.
The OutputCacheAttribute class in ASP.NET MVC requires a value for Duration and VaryByParam. I get why Duration is required, but not VaryByParam.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果他们不要求您进行配置,您可能会无意中获得同一页面的数万个缓存副本,从而使输出缓存的优势失效。
因此有两种解决方案——一是检查每个输出是否重复,二是使缓存依赖于某些与页面相关的变量的值。第一个可能成本太高,所以他们选择了第二个。
他们试图引导您进入“成功的深渊”,迫使您认识到,当存在某些查询字符串/POST 参数时,页面可能会以不同的方式呈现,并迫使您思考输出缓存的含义以及它是如何实现的。作品。
If they didn't require you configure this, you could unintentionally get tens of thousands of cached copies of the same exact page, thus invalidating the benefits of output caching.
Therefore there are two solutions--One, check each output to see if it is a duplicate, or two, make the cache dependent on the values of certain page-related variables. The first was probably too cost prohibitive, so they went with the second.
They're trying to guide you into the 'pit of success' by forcing you to realize that a page may be rendered differently when certain query string/POST parameters are present, and by forcing you to think about what output caching means and how it works.
更新:好的,从 MVC 的最新版本(3)开始,不再需要它,并且默认情况下不使用参数,即仅存在一次缓存。这是我之前预料到的行为。
Update: Ok, as of the latest release of MVC (3), it is no longer required and by default no params are used, i.e. only once cache exists. This is the behavior I had previously expected.