ASP .Net MVC 2.0 缓存问题
我在这样的操作上使用 OutputCache:
[OutputCache(Duration = 14400, VaryByParam = "none")]
public ContentResult Catalog()
{
return ...;
}
Global.asax.cs 中的 RegisterRoutes 函数包含路由:
routes.MapRoute(
"XMLRoute", // Route name
"{site}/catalog.xml", // URL with parameters
new { controller = "Home", action = "Catalog" } // Parameter defaults
);
路由映射 url 如下:
- example.com/site1/catalog.xml
- example.com/site2/catalog.xml
- 示例。 com/whatever/catalog.xml
到目录操作。
我相信预期的结果是在传递每个参数的第一个请求后返回静态内容,但内容未正确缓存。 我是否应该修改 Catalog 操作以使用参数,然后指定 VarybyParam = "none" 并在 MapRoute 函数中使用 UrlParameter.Optional 添加参数,或者这里还有其他情况吗?
I am using OutputCache on an Action like this:
[OutputCache(Duration = 14400, VaryByParam = "none")]
public ContentResult Catalog()
{
return ...;
}
and my RegisterRoutes function in Global.asax.cs contains the route:
routes.MapRoute(
"XMLRoute", // Route name
"{site}/catalog.xml", // URL with parameters
new { controller = "Home", action = "Catalog" } // Parameter defaults
);
The route maps urls like:
- example.com/site1/catalog.xml
- example.com/site2/catalog.xml
- example.com/whatever/catalog.xml
to the Catalog Action.
I believe that the expected result would be to return static content after the first request for every parameter passed, but the content is not cached properly.
Should I modify the Catalog action to use a param and then specify VarybyParam = "none" and add a param with UrlParameter.Optional at the MapRoute function or is there something else going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过多次试验和错误,我发现最好的方法是使用:
并使用重定向提供参数,以便使用默认值并显示缓存的内容。
After much trial and error I found that the best way was to use:
And provide the parameters using redirect so that the defaults are used and cached content is shown.