使用 [OutputCache] 提供对操作/页面的管理 - 在 mvc3 中
我们提出了 3 个选项,用于在操作/页面上提供带有缓存的管理按钮,并想知道是否还有其他选项或需要注意的性能/内存/可用性问题:
- Donut-hole 缓存 - http://haacked.com/archive/2009/05/12/donut-hole-caching.aspx
- VaryByCustom - http://visitmix.com/writings/using-varybycustom-with-outputcache-in-asp-net-mvc-to-support-caching-for-logged-in-users
- 创建单独的管理操作/pages
编辑:有没有办法“过载”操作?即,如果有一种方法可以为非管理员用户调用具有[OutputCache]属性的操作,并为管理员调用没有[OutputCache]属性的操作,那就太好了> 用户。
背景:我们有一个非常简单的博客,希望允许管理用户编辑/删除帖子并批准评论。因此,我们使用 asp.net MVC3 razor:根据用户角色显示操作链接 - ".If(User.IsInRole("Administrators"))"。
然后,我们将 [OutputCache(Duration = 30)] 添加到该操作中,发现每个人都会看到管理员版本或更简单的版本 - 取决于缓存超时后谁是第一个请求页面的人。呃……
We've come up with 3 options for providing administration buttons on Actions/pages with caching and would like to know if there are other options or performance/memory/usability issues to be aware of:
- Donut-hole caching - http://haacked.com/archive/2009/05/12/donut-hole-caching.aspx
- VaryByCustom - http://visitmix.com/writings/using-varybycustom-with-outputcache-in-asp-net-mvc-to-support-caching-for-logged-in-users
- Create separate Admin Actions/pages
EDIT: Is there a way to "Overload" Actions? i.e. It would be idea if there was a way to call an Action which has an [OutputCache] attribute for non-admin users and an Action with no [OutputCache] attribute for admin users.
Background: We have a very simple blog and wanted to allow Administrative users to Edit/Delete posts and to approve comments. So, we added buttons that are rendered only for administrative uses using the solution shown in asp.net MVC3 razor: display actionlink based on user role - ".If(User.IsInRole("Administrators"))".
Then, we added [OutputCache(Duration = 30)] to that Action and found that everone would see either the Admin version or the plainer - depending on who happened to be the first to request the page after the cache timed out. Duh...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们最终选择了选项“3.创建单独的管理操作/页面”。
这使我们可以选择创建单独的网站/子域进行管理并简化缓存结构 - 我们可能不会在管理页面上进行任何缓存。
We ended up choosing option "3.Create separate Admin Actions/pages".
This allows us the option of creating a separate website/subdomain for administration and simplifies the caching structure - we likely won't do any caching on the Admin pages.
这可能只是您问题编辑的部分答案:
AFAIK,您只能创建同一操作方法的 2 个重载:其中一个必须是 HttpPost,另一个必须是 HttpGet,并且它们(当然)必须具有要编译的不同参数。
This may only be a partial answer to your question edit:
AFAIK, you can only create 2 overloads of the same action method: one of them must be a HttpPost, and the other must be a HttpGet, and they (of course) must have different params to compile.