简体   繁体   English

ASP.NET缓存

[英]ASP.NET Caching

I can't seem to get it to "work". 我似乎无法让它“工作”。 Perhaps I'm not even testing it correctly. 也许我甚至没有正确测试它。 I've got a <%= DateTime.Now.ToString() %> line in my aspx page. 我的aspx页面中有一个<%= DateTime.Now.ToString()%>行。 I've tried setting caching declarativly like this 我已经尝试过像这样设置缓存

<%@ OutputCache VaryByParam="SchoolId" Duration="180" Location="Server" NoStore="false" %>

I've also tried setting it programmatically via the Response.Cache object. 我也尝试过通过Response.Cache对象以编程方式设置它。 The timestamp always changes. 时间戳总是在变化。

The web.config originally didn't have an outputCache section. web.config最初没有outputCache部分。 I've added one that looks like 我添加了一个看起来像

<outputCache enableOutputCache="true" enableFragmentCache="true" sendCacheControlHeader="true" omitVaryStar="false"/>

Always the timestamp changes. 始终是时间戳更改。 What do I try next? 接下来我该尝试什么?

ugh. 啊。 The issue was a Response.Cache.SetCacheability(HttpCacheability.NoCache) in the Page_Load of a usercontrol buried 3 levels deep from the page. 问题是位于页面深层3层的用户控件的Page_Load中的Response.Cache.SetCacheability(HttpCacheability.NoCache)。 I appreciate the help, though. 不过,我很感激你的帮助。

-al -al

It should be pretty easy to enable. 它应该很容易启用。 I've done it in the past by setting the OutputCache directive in my aspx. 我在过去通过在我的aspx中设置OutputCache指令来完成它。 I don't think the web.config changes are necessary, as caching is usually enabled by default. 我不认为web.config更改是必要的,因为默认情况下通常会启用缓存。

Are you testing with IIS or the dev web server? 您正在使用IIS或开发Web服务器进行测试吗? Are you doing anything that would cause the web server to reset (ie, doing a build) in between your tests? 您是否正在做任何会导致Web服务器在您的测试之间重置(即进行构建)的事情?

I don't think this will work because DateTime.Now is a property that is always updated. 我认为这不会起作用,因为DateTime.Now是一个始终更新的属性。 You'd have to save it in a different variable, otherwise fetch it from the cache. 您必须将其保存在另一个变量中,否则从缓存中获取它。

Hmm. 嗯。 My brain is kind of mush today. 我的大脑今天有点糊涂了。 I'm not sure if this is accurate since it is output caching, but I don't have time to mock up a sample right now. 我不确定这是否准确,因为它是输出缓存,但我现在没有时间模拟样本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM