在MVC使用的OutputCache [英] Using outputcache in MVC

查看:163
本文介绍了在MVC使用的OutputCache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经声明如下动作

[Route("{language}/Navigation/Test")]
[OutputCache(Duration = 3600, VaryByParam = "none")]
public ActionResult Test()
{
   return View();
}

为了检查的OutputCache设置我加入 @ DateTime.Now.Ticks.ToString()鉴于Test.cstml

In order to check outputcache setting I added @DateTime.Now.Ticks.ToString() in view Test.cstml

什么困扰我的是,当我运行的http://本地主机/ EN /导航/测试的第一时间,查看被缓存并刷新页面返回相同数量的刻度。现在,如果我改变语言,并设置的http://本地主机/ DE /导航/测试的蜱数量的变化, IE浏览器。视图不会从缓存中。

What troubles me is that when i run http://localhost/EN/Navigation/Test first time, view gets cached and page refresh returns a same number of ticks. Now if i change language and set http://localhost/DE/Navigation/Test number of tick changes, ie. view is not served from cache.

我试图删除的VaryByParam =无,但总是产生相同的结果。

I tried to remove VaryByParam = "none" but is always produces the same results.

什么是错在这里,如何为一个缓存的视图不能不管使用什么语言。

What is wrong here, how to serve a cached view not matter what language is used.

推荐答案

的VaryByParam 通过在URL传递的参数而异。即该URL www.stackoverflow.com/page?参数1 = 5 。因为 DE 是一个不同的URL EN ,该页面将不会在高速缓存中找到,因此请求新一。

VaryByParam varies by the parameters passed in a URL. I.e. The URL www.stackoverflow.com/page?param1=5. Because DE is a different URL to EN, the page won't be found in the cache so it requests a new one.

MSDN

用来改变输出缓存字符串的分号分隔的列表。默认情况下,这些字符串对应于具有GET方法的属性,或使用POST方法发送参数发送的查询字符串值。当该属性被设置为多个参数,输出缓存包含不同版本为每个指定的参数所请求文档的。可能的值包括无,*,任何有效的查询字符串或POST参数名称。

A semicolon-separated list of strings used to vary the output cache. By default, these strings correspond to a query string value sent with GET method attributes, or a parameter sent using the POST method. When this attribute is set to multiple parameters, the output cache contains a different version of the requested document for each specified parameter. Possible values include none, *, and any valid query string or POST parameter name.

底线:它基于URL,而不是路由。您可以根据查询字符串,但没有更多。

Bottom line: It's based on URL, not routing. You are able to configure based on the query string but no more.

这篇关于在MVC使用的OutputCache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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