2
votes

I am enabling output caching in my Sitecore-enabled ASP.NET site by putting this in my default.aspx (which lives outside the CMS):

<%@ OutputCache Duration="300" VaryByParam="None" %>

and in my Web.config:

<setting name="DisableBrowserCaching" value="false" />

This works when I hit my page directly, as in http://[website]/default.aspx, but not when I browse to the root site http://[website]/. In this case it always returns a 200 response, rather than 304 (not modified) on repeat requests.

I have tried the same in a website that does not use Sitecore, and caching works in all instances under IIS 7 and with Sitecore 6.4.1.

How do I enable output caching for default (extensionless) ASP.NET pages in a Sitecore-enabled site?

Update:
Seems to work on my local machine (this issue was in our QA environment), only difference I can see is that I have IIS 7.5 rather than 7.0, but same web.config and Sitecore instance.

Also, I have created another test page (http://[website]/Test/default.aspx) which exhibits the same behavior, so it is not only the root that is affected.

Update 2:
Bad news - Sitecore have confirmed that Output Caching is not officially supported:

"Sitecore CMS was not designed to work with enabled User-mode or Kernel-mode output caching in IIS and does not support its usage."

This doesn't explain why it sometimes works for specific URLs and environments, and I would still appreciate a workaround.

3
re: "Update" (the first one) Are your behavioral differences perhaps due to integrated vs classic mode app pools? - Paul George
Paul - both app pools are v4.0 Integrated - Dunc

3 Answers

1
votes

I did quick test and it looks like setting DisableBrowserCaching to false and adding OutputCache directive to the aspx layout file works fine.

Right, the response code is 200 OK, but the page is taken from the cache of the browser (not from the server). Response code 304 would mean that there was a call to the server and the server answered that nothing was changed.

Could you double check whether the code of the page is executed on the server side?

-1
votes

If using sitecore, you would need to put the directive into each of your layout (.aspx) files so that the presentation settings are always one of these layouts.

<%@ OutputCache Duration="300" VaryByParam="None" %> 

If your homepage was using a different layout minus the directive, it may explain the behavour.

That aside, it's likely that you will be better off using Sitecore's in built caching methods.

-2
votes

You need to enable caching on your public site in the web.config:

<Sites>
  <site name="website" cacheHtml="true" ... />

Normally ouput caching works on component level and is configured in Sitecore on the presentation.