【发布时间】:2011-02-07 05:19:38
【问题描述】:
我使用 OutputCache 配置文件设置了几个页面,并确认它们正在通过使用多个浏览器进行缓存,并请求检索具有与所有请求匹配的时间戳的页面。当我尝试枚举 HttpContect.Cache 时,它始终为空。
有什么想法吗?或者我应该去哪里获取这些信息?
更新:
这不是客户端缓存,因为多个浏览器看到相同的响应。这里有一些代码来解释发生了什么。
Web.Config 缓存设置
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<clear/>
<add name="StaticContent" duration="1200" varyByParam="none"/>
<add name="VaryByParam" duration="1200" varyByParam="*"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
...
</system.web>
**带有缓存的动作方法
[OutputCache(CacheProfile = "StaticContent")]
public ActionResult Index()
{
return View(new CollaborateModel());
}
枚举缓存的代码,是的,这很粗糙,这是在控制器操作方法中定义的
var sb = new StringBuilder();
foreach (KeyValuePair<string, object> item in HttpContext.Cache)
{
sb.AppendFormat("{0} : {1}<br />", item.Key, item.Value.ToString());
}
ViewData.Add("CacheContents", sb.ToString());
HttpContext.Cache 是计数始终为空的地方,即使缓存似乎工作正常。
【问题讨论】:
-
可能需要看一些代码。
标签: asp.net-mvc model-view-controller caching