我该如何配置不同的查询字符串值的OutputCache页属性? [英] How do I configure OutputCache page attribute for varying querystring values?

查看:116
本文介绍了我该如何配置不同的查询字符串值的OutputCache页属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个是这样

的http://本地主机/会计/产品ID = 234

和有时是这样:

的http://本地主机/会计/产品ID = 152

由于产品的项目不经常变化,我想缓存一个小时每一页为特定的产品ID。

Since product items does not change frequently, I want each pages for a particular product ID to be cached for an hour.

因此​​,对于第一次请求的页面将被缓存产品ID = 234和用于产品ID = 234小时内后续请求,将被从缓存中检索。在1小时后的下一个请求已经经过了产品ID = 234,一个新的页面将被从服务器从缓存中检索未。等等。

So for the first request the page will be cached for product id = 234 and succeeding request for the product id =234 within an hour, will be retrieved from the cache. The next request after 1 hour has elapsed for product id =234, a new page will be retrieved from the server not from the cache. And so on.

我怎么去呢?

推荐答案

奥弗泽里格柯的答案是正确的,但是当你使用MVC,正确的位置添加的OutputCache配置中的作用。

Ofer Zelig's answer is right, but as you are using MVC, the correct location to add the OutputCache configuration is in the action.

[OutputCache(Duration=3600, VaryByParam="id")]
public ActionResult Products(int id)
{
    //
    return View();
}

这篇关于我该如何配置不同的查询字符串值的OutputCache页属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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