views:

274

answers:

3
+1  Q: 

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. 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. The timestamp always changes.

The web.config originally didn't have an outputCache section. 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?

A: 

I don't think this will work because DateTime.Now is a property that is always updated. 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.

Steven Behnke
+1  A: 

It should be pretty easy to enable. I've done it in the past by setting the OutputCache directive in my aspx. I don't think the web.config changes are necessary, as caching is usually enabled by default.

Are you testing with IIS or the dev web server? Are you doing anything that would cause the web server to reset (ie, doing a build) in between your tests?

Jason
With the WebDev server I experience that it will not cache the first request. Other than that, I've allways got it working right without touching the web.config...
Arjan Einbu
+2  A: 

ugh. The issue was a Response.Cache.SetCacheability(HttpCacheability.NoCache) in the Page_Load of a usercontrol buried 3 levels deep from the page. I appreciate the help, though.

-al

Al W